Skip to content

Commit

Permalink
Merge branch 'main' into lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jsignell committed Nov 3, 2023
2 parents 5e08ce1 + f9034ac commit 9e12bdf
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 137 deletions.
71 changes: 15 additions & 56 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,63 +27,22 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
python-version: ["3.8", "3.11"]
python-version: ["3.9", "3.12"]
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
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 }}"
- 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/[email protected]
with:
file: ./coverage.xml
flags: unittests
env_vars: RUNNER_OS,PYTHON_VERSION
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@v3
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"
cache-environment: true
create-args: >-
python=${{ matrix.python-version }}
- name: Install cf_xarray
run: |
python -m pip install --no-deps -e .
Expand All @@ -106,16 +65,16 @@ 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
- 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 .
Expand All @@ -132,19 +91,19 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.8", "3.11"]
python-version: ["3.9", "3.12"]
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
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 .
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ 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
name: Install Python
with:
python-version: 3.8
python-version: "3.10"

- name: Install dependencies
run: |
Expand Down Expand Up @@ -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
Expand All @@ -72,7 +72,7 @@ jobs:
- name: Publish package to TestPyPI
if: github.event_name == 'push'
uses: pypa/[email protected].7
uses: pypa/[email protected].10
with:
password: ${{ secrets.TESTPYPI_TOKEN }}
repository_url: https://test.pypi.org/legacy/
Expand All @@ -96,6 +96,6 @@ jobs:
name: releases
path: dist
- name: Publish package to PyPI
uses: pypa/[email protected].7
uses: pypa/[email protected].10
with:
verbose: true
2 changes: 1 addition & 1 deletion .github/workflows/testpypi-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/upstream-dev-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@ 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@v3
- 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
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 .
Expand Down
32 changes: 23 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@ 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.0.276'
rev: 'v0.1.1'
hooks:
- id: ruff
args: ["--fix"]
args: ["--show-fixes", "--fix"]

- repo: https://github.com/psf/black
rev: 23.3.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.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:
Expand All @@ -38,10 +44,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
Expand All @@ -61,6 +67,14 @@ repos:
- id: validate-cff

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.13
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
23 changes: 10 additions & 13 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -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: []
27 changes: 17 additions & 10 deletions cf_xarray/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -2301,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:
Expand Down
5 changes: 3 additions & 2 deletions cf_xarray/criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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": (
Expand Down
Loading

0 comments on commit 9e12bdf

Please sign in to comment.