From cbf57dfcef0992dac2b36b385232da9f2f9330b2 Mon Sep 17 00:00:00 2001 From: Filipe Date: Wed, 9 Aug 2023 15:42:19 -0300 Subject: [PATCH 01/11] remove distutils (#463) * remove distutils * should be OK --- cf_xarray/tests/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cf_xarray/tests/__init__.py b/cf_xarray/tests/__init__.py index b2a0e3eb..f74aad33 100644 --- a/cf_xarray/tests/__init__.py +++ b/cf_xarray/tests/__init__.py @@ -1,10 +1,10 @@ import importlib import re from contextlib import contextmanager -from distutils import version import dask import pytest +from packaging import version @contextmanager @@ -60,7 +60,7 @@ def LooseVersion(vstring): # Our development version is something like '0.10.9+aac7bfc' # This function just ignored the git commit id. vstring = vstring.split("+")[0] - return version.LooseVersion(vstring) + return version.parse(vstring) has_cftime, requires_cftime = _importorskip("cftime") From 24e22cf112dfc04fafc0202cc0eeea3c105c6c19 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 3 Sep 2023 06:10:52 +0530 Subject: [PATCH 02/11] Bump pypa/gh-action-pypi-publish from 1.8.7 to 1.8.10 (#466) Bumps [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) from 1.8.7 to 1.8.10. - [Release notes](https://github.com/pypa/gh-action-pypi-publish/releases) - [Commits](https://github.com/pypa/gh-action-pypi-publish/compare/v1.8.7...v1.8.10) --- updated-dependencies: - dependency-name: pypa/gh-action-pypi-publish dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/pypi.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pypi.yaml b/.github/workflows/pypi.yaml index 6e59ef7a..5ebbbdff 100644 --- a/.github/workflows/pypi.yaml +++ b/.github/workflows/pypi.yaml @@ -72,7 +72,7 @@ jobs: - name: Publish package to TestPyPI if: github.event_name == 'push' - uses: pypa/gh-action-pypi-publish@v1.8.7 + uses: pypa/gh-action-pypi-publish@v1.8.10 with: password: ${{ secrets.TESTPYPI_TOKEN }} repository_url: https://test.pypi.org/legacy/ @@ -96,6 +96,6 @@ jobs: name: releases path: dist - name: Publish package to PyPI - uses: pypa/gh-action-pypi-publish@v1.8.7 + uses: pypa/gh-action-pypi-publish@v1.8.10 with: verbose: true From d15ea92362cc79c996377f55abe54bc8b93717b5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 1 Oct 2023 19:02:36 -0600 Subject: [PATCH 03/11] Bump actions/checkout from 3 to 4 (#470) Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3...v4) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/ci.yaml | 8 ++++---- .github/workflows/pypi.yaml | 2 +- .github/workflows/testpypi-release.yaml | 2 +- .github/workflows/upstream-dev-ci.yaml | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2635bf27..48d39183 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -29,7 +29,7 @@ jobs: os: ["ubuntu-latest"] python-version: ["3.8", "3.11"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all history for all branches and tags. - name: Set environment variables @@ -69,7 +69,7 @@ jobs: matrix: python-version: ["3.10"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all history for all branches and tags. - name: Set environment variables @@ -106,7 +106,7 @@ jobs: run: shell: bash -l {0} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: # need to fetch all tags to get a correct version fetch-depth: 0 # fetch all branches and tags @@ -134,7 +134,7 @@ jobs: matrix: python-version: ["3.8", "3.11"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all history for all branches and tags. - name: Set up conda environment diff --git a/.github/workflows/pypi.yaml b/.github/workflows/pypi.yaml index 5ebbbdff..f59a5a81 100644 --- a/.github/workflows/pypi.yaml +++ b/.github/workflows/pypi.yaml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest if: github.repository == 'xarray-contrib/cf-xarray' steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - uses: actions/setup-python@v4 diff --git a/.github/workflows/testpypi-release.yaml b/.github/workflows/testpypi-release.yaml index f2ec72f5..9df46af5 100644 --- a/.github/workflows/testpypi-release.yaml +++ b/.github/workflows/testpypi-release.yaml @@ -17,7 +17,7 @@ jobs: if: ${{ contains( github.event.pull_request.labels.*.name, 'test-build') && github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 diff --git a/.github/workflows/upstream-dev-ci.yaml b/.github/workflows/upstream-dev-ci.yaml index 13cd1922..4128dd32 100644 --- a/.github/workflows/upstream-dev-ci.yaml +++ b/.github/workflows/upstream-dev-ci.yaml @@ -31,7 +31,7 @@ jobs: matrix: python-version: ["3.11"] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all history for all branches and tags. - name: Set environment variables From 0f0e997f96d3f00a3b8cce7304690fb5030c6f05 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 3 Oct 2023 00:18:55 -0600 Subject: [PATCH 04/11] [pre-commit.ci] pre-commit autoupdate (#471) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.0.276 → v0.0.292](https://github.com/astral-sh/ruff-pre-commit/compare/v0.0.276...v0.0.292) - [github.com/psf/black: 23.3.0 → 23.9.1](https://github.com/psf/black/compare/23.3.0...23.9.1) - [github.com/rstcheck/rstcheck: v6.1.2 → v6.2.0](https://github.com/rstcheck/rstcheck/compare/v6.1.2...v6.2.0) - [github.com/executablebooks/mdformat: 0.7.16 → 0.7.17](https://github.com/executablebooks/mdformat/compare/0.7.16...0.7.17) - [github.com/abravalheri/validate-pyproject: v0.13 → v0.14](https://github.com/abravalheri/validate-pyproject/compare/v0.13...v0.14) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 45e8f9a1..a857ac41 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,25 +4,25 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: 'v0.0.276' + rev: 'v0.0.292' hooks: - id: ruff args: ["--fix"] - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.9.1 hooks: - id: black - repo: https://github.com/rstcheck/rstcheck - rev: v6.1.2 + rev: v6.2.0 hooks: - id: rstcheck additional_dependencies: [sphinx, tomli] args: ['--config', 'pyproject.toml'] - repo: https://github.com/executablebooks/mdformat - rev: 0.7.16 + rev: 0.7.17 hooks: - id: mdformat additional_dependencies: @@ -61,6 +61,6 @@ repos: - id: validate-cff - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.13 + rev: v0.14 hooks: - id: validate-pyproject From e3254bd71cdee81605767e781422ef9bca0f2152 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Tue, 24 Oct 2023 12:01:06 -0600 Subject: [PATCH 05/11] Address some repo-review comments. (#474) * Address some repo-review comments. * update * Add pygrep-hooks * Fix rst --- .pre-commit-config.yaml | 22 +++++++++++++++------- doc/whats-new.rst | 6 +++--- pyproject.toml | 1 - 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a857ac41..a6cdd8fd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,13 +4,13 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. - rev: 'v0.0.292' + rev: 'v0.1.1' hooks: - id: ruff - args: ["--fix"] + args: ["--show-fixes", "--fix"] - - repo: https://github.com/psf/black - rev: 23.9.1 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 23.10.1 hooks: - id: black @@ -38,10 +38,10 @@ repos: entry: nbqa mdformat name: nbqa-mdformat alias: nbqa-mdformat - additional_dependencies: [mdformat==0.7.14] + additional_dependencies: [mdformat==0.7.17] - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -61,6 +61,14 @@ repos: - id: validate-cff - repo: https://github.com/abravalheri/validate-pyproject - rev: v0.14 + rev: v0.15 hooks: - id: validate-pyproject + + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 + hooks: + # - id: python-check-blanket-type-ignore + - id: rst-backticks + - id: rst-directive-colons + - id: rst-inline-touching-normal diff --git a/doc/whats-new.rst b/doc/whats-new.rst index ec1f7bf6..3a916800 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -42,7 +42,7 @@ v0.7.9 (Jan 31, 2023) v0.7.8 (Jan 31, 2023) ===================== -- Optionally use the `regex` package to continue supporting global flags in regular expressions that are not at start of pattern (:pr:`408`). By `Kristen Thyng`_ +- Optionally use the ``regex`` package to continue supporting global flags in regular expressions that are not at start of pattern (:pr:`408`). By `Kristen Thyng`_ - Added link to docs for a new example "COSIMA ocean-sea ice model demo" (:pr:`397`). By `Aidan Heerdegen`_ v0.7.7 (Jan 14, 2023) @@ -82,7 +82,7 @@ v0.7.4 (July 14, 2022) v0.7.3 (June 30, 2022) ====================== - :py:meth:`Dataset.cf.guess_coord_axis` now skips known axes/coordinates and only returns a single guess per variable. - Additional attributes such as `units` must be added to known axes/coordinates using :py:meth:`Dataset.cf.add_canonical_attributes`. + Additional attributes such as ``units`` must be added to known axes/coordinates using :py:meth:`Dataset.cf.add_canonical_attributes`. By `Mattia Almansi`_. - Increased support for ``cf_role`` variables. Added :py:attr:`Dataset.cf.cf_roles` By `Deepak Cherian`_. @@ -126,7 +126,7 @@ v0.6.0 (June 29, 2021) - Begin adding support for units with a unit registry for pint arrays. :pr:`197`. By `Jon Thielen`_ and `Justus Magin`_. - :py:meth:`Dataset.cf.rename_like` also updates the ``bounds`` and ``cell_measures`` attributes. By `Mattia Almansi`_. -- Support of custom vocabularies/criteria: user can input criteria for identifying variables by their name and attributes to be able to refer to them by custom names like `ds.cf["ssh"]`. :pr:`234`. By `Kristen Thyng`_ and `Deepak Cherian`_. +- Support of custom vocabularies/criteria: user can input criteria for identifying variables by their name and attributes to be able to refer to them by custom names like ``ds.cf["ssh"]``. :pr:`234`. By `Kristen Thyng`_ and `Deepak Cherian`_. v0.5.2 (May 11, 2021) ===================== diff --git a/pyproject.toml b/pyproject.toml index 5171635f..7bc789ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,7 +35,6 @@ requires = [ # xarray is need for dynamic version string "xarray", "setuptools>=45", - "wheel", "setuptools_scm[toml]>=6.2", ] build-backend = "setuptools.build_meta" From c4d662edad0062f3130d7aa12cd3e48d42d114ab Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Tue, 24 Oct 2023 14:05:57 -0600 Subject: [PATCH 06/11] Bump to py3.9, test py3.12 (#475) * Bump to py3.9, test py3.12 * fix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * cleanup warnings / speed up * Silence warning * Bump sphinx * Handle the `_deprecate_positional_kwargs` decorator * Add min xarray * Typing fixes * revert one * More bumps * update RTD yaml * fix? * skip unshallow fetch * try again * install local cf-xarray * try again * print sphinx version * see if furo in pip overrides * yet agauin * again * Switich ot py 3.10 * try typing * try again * update pypi workflow --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .github/workflows/ci.yaml | 45 ++------------------------------ .github/workflows/pypi.yaml | 4 +-- .pre-commit-config.yaml | 6 +++++ .readthedocs.yml | 23 +++++++--------- cf_xarray/accessor.py | 13 +++------ cf_xarray/criteria.py | 5 ++-- cf_xarray/formatting.py | 6 ++--- cf_xarray/geometry.py | 2 +- cf_xarray/helpers.py | 2 +- cf_xarray/options.py | 3 ++- cf_xarray/scripts/make_doc.py | 4 +-- cf_xarray/tests/test_accessor.py | 26 +++++++++++------- cf_xarray/utils.py | 5 ++-- ci/doc.yml | 6 ++--- doc/conf.py | 2 +- pyproject.toml | 8 +++--- 16 files changed, 63 insertions(+), 97 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 48d39183..9506733b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -27,7 +27,7 @@ jobs: fail-fast: false matrix: os: ["ubuntu-latest"] - python-version: ["3.8", "3.11"] + python-version: ["3.9", "3.12"] steps: - uses: actions/checkout@v4 with: @@ -58,47 +58,6 @@ jobs: name: codecov-umbrella fail_ci_if_error: false - old-xarray: - name: xarray 2022.03.0 - runs-on: "ubuntu-latest" - defaults: - run: - shell: bash -l {0} - strategy: - fail-fast: false - matrix: - python-version: ["3.10"] - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Fetch all history for all branches and tags. - - name: Set environment variables - run: | - echo "PYTHON_VERSION=${{ matrix.python-version }}" >> $GITHUB_ENV - - name: Set up conda environment - uses: mamba-org/provision-with-micromamba@v15 - with: - environment-file: ci/environment.yml - environment-name: cf_xarray_test - cache-env: true - extra-specs: | - python="${{ matrix.python-version }}" - xarray="2022.03.0" - - name: Install cf_xarray - run: | - python -m pip install --no-deps -e . - - name: Run Tests - run: | - pytest -n auto --cov=./ --cov-report=xml - - name: Upload code coverage to Codecov - uses: codecov/codecov-action@v3.1.4 - with: - file: ./coverage.xml - flags: unittests - env_vars: RUNNER_OS,PYTHON_VERSION - name: codecov-umbrella - fail_ci_if_error: false - no-optional-deps: name: no-optional-deps runs-on: ubuntu-latest @@ -132,7 +91,7 @@ jobs: shell: bash -l {0} strategy: matrix: - python-version: ["3.8", "3.11"] + python-version: ["3.9", "3.12"] steps: - uses: actions/checkout@v4 with: diff --git a/.github/workflows/pypi.yaml b/.github/workflows/pypi.yaml index f59a5a81..0e70f0ea 100644 --- a/.github/workflows/pypi.yaml +++ b/.github/workflows/pypi.yaml @@ -18,7 +18,7 @@ jobs: - uses: actions/setup-python@v4 name: Install Python with: - python-version: 3.8 + python-version: 3.10 - name: Install dependencies run: | @@ -53,7 +53,7 @@ jobs: - uses: actions/setup-python@v4 name: Install Python with: - python-version: 3.8 + python-version: 3.10 - uses: actions/download-artifact@v3 with: name: releases diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a6cdd8fd..b1c2e527 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,6 +2,12 @@ ci: autoupdate_schedule: quarterly repos: + - repo: https://github.com/asottile/pyupgrade + rev: v3.15.0 + hooks: + - id: pyupgrade + args: ["--py39-plus"] + - repo: https://github.com/astral-sh/ruff-pre-commit # Ruff version. rev: 'v0.1.1' diff --git a/.readthedocs.yml b/.readthedocs.yml index 2013acc6..c2cb5520 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,20 +1,17 @@ -# Required version: 2 build: - os: 'ubuntu-20.04' + os: ubuntu-22.04 tools: - python: 'mambaforge-4.10' + python: mambaforge-4.10 + jobs: + post_checkout: + - (git --no-pager log --pretty="tformat:%s" -1 | grep -vqF "[skip-rtd]") || exit 183 + pre_install: + - conda list sphinx + - conda list cf_xarray -# Build documentation in the docs/ directory with Sphinx -sphinx: - configuration: doc/conf.py - -# Optionally set the version of Python and requirements required to build your docs conda: - environment: ci/doc.yml + environment: ci/doc.yml -python: - install: - - method: pip - path: . +formats: [] diff --git a/cf_xarray/accessor.py b/cf_xarray/accessor.py index ffe68ee9..e77ba9d3 100644 --- a/cf_xarray/accessor.py +++ b/cf_xarray/accessor.py @@ -6,16 +6,11 @@ import re import warnings from collections import ChainMap, namedtuple +from collections.abc import Hashable, Iterable, Mapping, MutableMapping, Sequence from datetime import datetime from typing import ( Any, Callable, - Hashable, - Iterable, - List, - Mapping, - MutableMapping, - Sequence, TypeVar, Union, cast, @@ -84,7 +79,7 @@ ATTRS["vertical"] = ATTRS["Z"] # Type for Mapper functions -Mapper = Callable[[Union[DataArray, Dataset], Hashable], List[Hashable]] +Mapper = Callable[[Union[DataArray, Dataset], Hashable], list[Hashable]] # Type for decorators F = TypeVar("F", bound=Callable[..., Any]) @@ -496,7 +491,7 @@ def _get_coords(obj: DataArray | Dataset, key: Hashable) -> list[Hashable]: def _variables(func: F) -> F: @functools.wraps(func) def wrapper(obj: DataArray | Dataset, key: Hashable) -> list[DataArray]: - return [obj[k] for k in func(obj, key)] # type: ignore + return [obj[k] for k in func(obj, key)] # type: ignore[misc] return cast(F, wrapper) @@ -1293,7 +1288,7 @@ def _process_signature( This uses ``key_mappers`` 3. Unpacks arguments if necessary before returning them. """ - sig = inspect.signature(func, follow_wrapped=False) + sig = inspect.signature(func, follow_wrapped=True) # Catch things like .isel(T=5). # This assigns indexers_kwargs=dict(T=5). diff --git a/cf_xarray/criteria.py b/cf_xarray/criteria.py index 88c3ba4d..f6bfc56e 100644 --- a/cf_xarray/criteria.py +++ b/cf_xarray/criteria.py @@ -9,7 +9,8 @@ except ImportError: import re # type: ignore -from typing import Any, Mapping, MutableMapping, Tuple +from collections.abc import Mapping, MutableMapping +from typing import Any _DSG_ROLES = ["timeseries_id", "profile_id", "trajectory_id"] @@ -30,7 +31,7 @@ "grid_mapping": {"grid_mapping_name": re.compile(".")} } -coordinate_criteria: MutableMapping[str, MutableMapping[str, Tuple]] = { +coordinate_criteria: MutableMapping[str, MutableMapping[str, tuple]] = { "latitude": { "standard_name": ("latitude",), "units": ( diff --git a/cf_xarray/formatting.py b/cf_xarray/formatting.py index ed05b2c6..c700924c 100644 --- a/cf_xarray/formatting.py +++ b/cf_xarray/formatting.py @@ -1,6 +1,6 @@ import warnings +from collections.abc import Hashable, Iterable from functools import partial -from typing import Dict, Hashable, Iterable, List import numpy as np @@ -56,7 +56,7 @@ def make_text_section( warnings.simplefilter("ignore") if isinstance(attr, str): try: - vardict: Dict[str, Iterable[Hashable]] = getattr(accessor, attr, {}) + vardict: dict[str, Iterable[Hashable]] = getattr(accessor, attr, {}) except ValueError: vardict = {} else: @@ -103,7 +103,7 @@ def make_text_section( return _print_rows(subtitle, rows, rich) -def _print_rows(subtitle: str, rows: List[str], rich: bool): +def _print_rows(subtitle: str, rows: list[str], rich: bool): subtitle = f"{subtitle.rjust(20)}:" # Add subtitle to the first row, align other rows diff --git a/cf_xarray/geometry.py b/cf_xarray/geometry.py index 56000858..148a8d1b 100644 --- a/cf_xarray/geometry.py +++ b/cf_xarray/geometry.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Sequence +from collections.abc import Sequence import numpy as np import pandas as pd diff --git a/cf_xarray/helpers.py b/cf_xarray/helpers.py index bda89ee7..5d5a7989 100644 --- a/cf_xarray/helpers.py +++ b/cf_xarray/helpers.py @@ -1,6 +1,6 @@ from __future__ import annotations -from typing import Hashable, Sequence +from collections.abc import Hashable, Sequence import numpy as np import xarray as xr diff --git a/cf_xarray/options.py b/cf_xarray/options.py index b642e4fa..75749a10 100644 --- a/cf_xarray/options.py +++ b/cf_xarray/options.py @@ -3,7 +3,8 @@ """ import copy -from typing import Any, MutableMapping +from collections.abc import MutableMapping +from typing import Any from .utils import always_iterable diff --git a/cf_xarray/scripts/make_doc.py b/cf_xarray/scripts/make_doc.py index 2f2e6f5f..b9e87909 100644 --- a/cf_xarray/scripts/make_doc.py +++ b/cf_xarray/scripts/make_doc.py @@ -29,7 +29,7 @@ def make_criteria_csv(): # Criteria tables df = DataFrame.from_dict(coordinate_criteria) df = df.dropna(axis=1, how="all") - df = df.applymap(lambda x: ", ".join(sorted(x)) if isinstance(x, tuple) else x) + df = df.map(lambda x: ", ".join(sorted(x)) if isinstance(x, tuple) else x) df = df.sort_index(axis=0).sort_index(axis=1) # All criteria @@ -51,7 +51,7 @@ def make_regex_csv(): csv_dir = "_build/csv" os.makedirs(csv_dir, exist_ok=True) df = DataFrame(regex, index=[0]) - df = df.applymap(lambda x: f"``{str(x)[11:-1]}``") + df = df.map(lambda x: f"``{str(x)[11:-1]}``") df = df.sort_index(axis=1).transpose() df.to_csv(os.path.join(csv_dir, "all_regex.csv"), header=False) diff --git a/cf_xarray/tests/test_accessor.py b/cf_xarray/tests/test_accessor.py index 8cbdf0f7..5761e500 100644 --- a/cf_xarray/tests/test_accessor.py +++ b/cf_xarray/tests/test_accessor.py @@ -326,7 +326,7 @@ def test_accessor_getattr_and_describe() -> None: "areacella", ) ) - ds_vertb = xr.decode_cf(vert, decode_coords="all") # type: ignore + ds_vertb = xr.decode_cf(vert, decode_coords="all") assert ds_verta.cf.cell_measures == ds_vertb.cf.cell_measures assert ds_verta.o3.cf.cell_measures == ds_vertb.o3.cf.cell_measures @@ -591,6 +591,7 @@ def test_dataarray_plot() -> None: rv = obj.isel(time=1).transpose("lon", "lat").cf.plot() assert isinstance(rv, mpl.collections.QuadMesh) + assert rv.axes is not None assert all(v > 180 for v in rv.axes.get_xlim()) assert all(v < 200 for v in rv.axes.get_ylim()) plt.close() @@ -845,8 +846,12 @@ def test_add_bounds_nd_variable() -> None: # 2D expected = ( - vertices_to_bounds( - np.arange(0, 13, 3).reshape(5, 1) + np.arange(-2, 2).reshape(1, 4) # type: ignore + vertices_to_bounds( # type: ignore + xr.DataArray( + np.arange(0, 13, 3).reshape(5, 1) + np.arange(-2, 2).reshape(1, 4), + dims=("x", "y"), + ), + out_dims=("bounds", "x", "y"), ) .rename("z_bounds") .assign_coords(**ds.coords) @@ -1890,7 +1895,8 @@ def test_missing_variables() -> None: assert ds.cf.bounds == {"lat": ["lat_bounds"], "latitude": ["lat_bounds"]} with pytest.raises(KeyError, match=r"No results found for 'longitude'."): - ds.cf.get_bounds("longitude") + with pytest.warns(UserWarning, match="not found in object"): + ds.cf.get_bounds("longitude") # Cell measures ds = airds.copy(deep=False) @@ -1945,18 +1951,18 @@ def line(time, slope): t = (time - time[0]).astype(float) return slope * t - actual = airds.air.cf.isel(lat=4, lon=5).curvefit(coords=("time",), func=line) - expected = airds.air.cf.isel(lat=4, lon=5).cf.curvefit(coords="T", func=line) + da = airds.air.cf.isel(lat=3, lon=3) + expected = da.curvefit(coords=("time",), func=line) + actual = da.cf.curvefit(coords="T", func=line) assert_identical(expected, actual) def plane(coords, slopex, slopey): x, y = coords return slopex * (x - x.mean()) + slopey * (y - y.mean()) - actual = airds.air.isel(time=0).curvefit(coords=("lat", "lon"), func=plane) - expected = airds.air.isel(time=0).cf.curvefit( - coords=["latitude", "longitude"], func=plane - ) + da = airds.air.cf.isel(time=0) + actual = da.curvefit(coords=("lat", "lon"), func=plane) + expected = da.cf.curvefit(coords=["latitude", "longitude"], func=plane) assert_identical(expected, actual) diff --git a/cf_xarray/utils.py b/cf_xarray/utils.py index 61752390..df5bb531 100644 --- a/cf_xarray/utils.py +++ b/cf_xarray/utils.py @@ -1,5 +1,6 @@ from collections import defaultdict -from typing import Any, Dict, Iterable +from collections.abc import Iterable +from typing import Any from xml.etree import ElementTree import numpy as np @@ -42,7 +43,7 @@ def _is_datetime_like(da: DataArray) -> bool: return False -def parse_cell_methods_attr(attr: str) -> Dict[str, str]: +def parse_cell_methods_attr(attr: str) -> dict[str, str]: """ Parse cell_methods attributes (format is 'measure: name'). diff --git a/ci/doc.yml b/ci/doc.yml index 4ed670a8..9481e505 100644 --- a/ci/doc.yml +++ b/ci/doc.yml @@ -3,7 +3,7 @@ channels: - conda-forge dependencies: - pip - - python=3.11 + - python=3.10 - matplotlib-base - netcdf4 - pooch @@ -20,6 +20,6 @@ dependencies: - pint - regex - furo + - myst-nb - pip: - - git+https://github.com/xarray-contrib/cf-xarray - - myst_nb + - -e ../ diff --git a/doc/conf.py b/doc/conf.py index 6f2f267a..87c17e74 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -33,7 +33,7 @@ # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. -# needs_sphinx = '1.0' +# needs_sphinx = "6.0" # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. diff --git a/pyproject.toml b/pyproject.toml index 7bc789ce..f9c9150a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,10 +11,10 @@ classifiers = [ "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ] dependencies = [ "xarray", @@ -33,7 +33,7 @@ changelog = "https://cf-xarray.readthedocs.io/en/latest/whats-new.html" [build-system] requires = [ # xarray is need for dynamic version string - "xarray", + "xarray>=2022.03.0", "setuptools>=45", "setuptools_scm[toml]>=6.2", ] @@ -55,10 +55,10 @@ write_to_template= '__version__ = "{version}"' tag_regex= "^(?Pv)?(?P[^\\+]+)(?P.*)?$" [tool.black] -target-version = ["py38"] +target-version = ["py39"] [tool.ruff] -target-version = "py38" +target-version = "py39" builtins = ["ellipsis"] exclude = [ ".eggs", From 03583e419848c019d391d20726be100a8b01a365 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Tue, 24 Oct 2023 14:17:18 -0600 Subject: [PATCH 07/11] Fix get_bounds_dim_name regression. (#473) Handle the case where `lat` and `lat_bounds` have same attributes. Closes #442 --- cf_xarray/accessor.py | 14 +++++++++++++- cf_xarray/tests/test_accessor.py | 8 ++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/cf_xarray/accessor.py b/cf_xarray/accessor.py index e77ba9d3..648f8748 100644 --- a/cf_xarray/accessor.py +++ b/cf_xarray/accessor.py @@ -2296,8 +2296,20 @@ def get_bounds_dim_name(self, key: Hashable) -> Hashable: ------- str """ - (crd_name,) = apply_mapper(_get_all, self._obj, key, error=False, default=[key]) + # In many cases, the bounds variable has the same attrs as the coordinate variable + # So multiple matches are possible. + crd_names = apply_mapper(_get_all, self._obj, key, error=False, default=[key]) + variables = self._obj._variables + filtered = [ + crd_name for crd_name in crd_names if "bounds" in variables[crd_name].attrs + ] + if len(filtered) > 1: + raise KeyError( + f"Received multiple matches for {key!r} that have a bounds attribute: {filtered!r} " + ) + + (crd_name,) = filtered crd = variables[crd_name] crd_attrs = crd._attrs if crd_attrs is None or "bounds" not in crd_attrs: diff --git a/cf_xarray/tests/test_accessor.py b/cf_xarray/tests/test_accessor.py index 5761e500..85ac2787 100644 --- a/cf_xarray/tests/test_accessor.py +++ b/cf_xarray/tests/test_accessor.py @@ -974,6 +974,14 @@ def test_get_bounds_dim_name() -> None: assert mollwds.cf.get_bounds_dim_name("longitude") == "bounds" assert mollwds.cf.get_bounds_dim_name("lon") == "bounds" + # Be OK with bounds and coordinates having same attributes + # GH442 + assert vert.cf.get_bounds_dim_name("longitude") == "bnds" + ds = vert.copy(deep=True) + ds.lat.attrs["standard_name"] = "longitude" + with pytest.raises(KeyError): + ds.cf.get_bounds_dim_name("longitude") + def test_grid_mappings(): ds = rotds.copy(deep=False) From 256f11c344404a5f77659ae70ceed7a267a9ee07 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Tue, 24 Oct 2023 14:45:21 -0600 Subject: [PATCH 08/11] Switch to setup-micromamba (#476) * Switch to setup-micromamba * Update .github/workflows/ci.yaml * fix? * last one! --- .github/workflows/ci.yaml | 20 ++++++++++---------- .github/workflows/upstream-dev-ci.yaml | 10 +++++----- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9506733b..5a8657b9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -36,13 +36,13 @@ jobs: run: | echo "PYTHON_VERSION=${{ matrix.python-version }}" >> $GITHUB_ENV - name: Set up conda environment - uses: mamba-org/provision-with-micromamba@v15 + uses: mamba-org/setup-micromamba@v1 with: environment-file: ci/environment.yml environment-name: cf_xarray_test - cache-env: true - extra-specs: | - python="${{ matrix.python-version }}" + cache-environment: true + create-args: >- + python=${{ matrix.python-version }} - name: Install cf_xarray run: | python -m pip install --no-deps -e . @@ -70,11 +70,11 @@ jobs: # need to fetch all tags to get a correct version fetch-depth: 0 # fetch all branches and tags - name: Set up conda environment - uses: mamba-org/provision-with-micromamba@v15 + uses: mamba-org/setup-micromamba@v1 with: environment-file: ci/environment-no-optional-deps.yml environment-name: cf_xarray_test - cache-env: true + cache-environment: true - name: Install cf_xarray run: | python -m pip install --no-deps -e . @@ -97,13 +97,13 @@ jobs: with: fetch-depth: 0 # Fetch all history for all branches and tags. - name: Set up conda environment - uses: mamba-org/provision-with-micromamba@v15 + uses: mamba-org/setup-micromamba@v1 with: environment-file: ci/environment.yml environment-name: cf_xarray_test - cache-env: true - extra-specs: | - python="${{ matrix.python-version }}" + cache-environment: true + create-args: >- + python=${{ matrix.python-version }} - name: Install cf_xarray run: | python -m pip install --no-deps -e . diff --git a/.github/workflows/upstream-dev-ci.yaml b/.github/workflows/upstream-dev-ci.yaml index 4128dd32..9923774a 100644 --- a/.github/workflows/upstream-dev-ci.yaml +++ b/.github/workflows/upstream-dev-ci.yaml @@ -22,14 +22,14 @@ jobs: upstream-dev: name: upstream-dev runs-on: ubuntu-latest - if: ${{ contains( github.event.pull_request.labels.*.name, 'test-upstream') && github.event_name == 'pull_request' || github.event_name == 'workflow_dispatch' }} + if: ${{ (contains( github.event.pull_request.labels.*.name, 'test-upstream') && github.event_name == 'pull_request') || github.event_name == 'workflow_dispatch' }} defaults: run: shell: bash -l {0} strategy: fail-fast: false matrix: - python-version: ["3.11"] + python-version: ["3.12"] steps: - uses: actions/checkout@v4 with: @@ -38,13 +38,13 @@ jobs: run: | echo "PYTHON_VERSION=${{ matrix.python-version }}" >> $GITHUB_ENV - name: Set up conda environment - uses: mamba-org/provision-with-micromamba@v15 + uses: mamba-org/setup-micromamba@v1 with: environment-file: ci/upstream-dev-env.yml environment-name: cf_xarray_test cache-env: False - extra-specs: | - python="${{ matrix.python-version }}" + create-args: >- + python=${{ matrix.python-version }} - name: Install cf_xarray run: | python -m pip install --no-deps -e . From 8779ba80a3787cd0777409314367e59353af547f Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Tue, 24 Oct 2023 15:05:07 -0600 Subject: [PATCH 09/11] v0.8.3: Update whats-new.rst (#477) --- doc/whats-new.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 3a916800..9660db5b 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -3,6 +3,10 @@ What's New ---------- +v0.8.5 (Oct 24, 2023) +===================== +- Fix for ``get_bounds_dim_name``. By `Deepak Cherian`_. + v0.8.2 (July 05, 2023) ====================== - Better reprs for flag masks. By `Deepak Cherian`_. From eb5b7e646844bf304a574ebef01ac2dcd2a82829 Mon Sep 17 00:00:00 2001 From: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> Date: Thu, 2 Nov 2023 16:18:20 -0400 Subject: [PATCH 10/11] Set python-version as string (#479) --- .github/workflows/pypi.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pypi.yaml b/.github/workflows/pypi.yaml index 0e70f0ea..99d3c3e1 100644 --- a/.github/workflows/pypi.yaml +++ b/.github/workflows/pypi.yaml @@ -18,7 +18,7 @@ jobs: - uses: actions/setup-python@v4 name: Install Python with: - python-version: 3.10 + python-version: "3.10" - name: Install dependencies run: | @@ -53,7 +53,7 @@ jobs: - uses: actions/setup-python@v4 name: Install Python with: - python-version: 3.10 + python-version: "3.10" - uses: actions/download-artifact@v3 with: name: releases From f9034ac04690161ca213996c158ff59b64dec054 Mon Sep 17 00:00:00 2001 From: Deepak Cherian Date: Thu, 2 Nov 2023 15:58:09 -0600 Subject: [PATCH 11/11] Update pyproject.toml to `python>=3.9` --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f9c9150a..a9494f75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ name = "cf_xarray" description = "A convenience wrapper for using CF attributes on xarray objects" readme = "README.rst" -requires-python = ">=3.8" +requires-python = ">=3.9" license = {file = "LICENSE"} keywords = ["xarray", "metadata", "CF conventions"] classifiers = [