Skip to content
forked from pydata/xarray

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into groupby-cumsum
Browse files Browse the repository at this point in the history
* upstream/main:
  Add a slighly cheesy contributors panel to readme (pydata#6520)
  Fix doctest & mypy CI jobs (pydata#6535)
  Attempt to improve CI caching (pydata#6534)
  Attempt to consolidate tests in CI (pydata#6533)
  Restrict annotations to a single run in GHA (pydata#6532)
  Fix some mypy issues (pydata#6531)
  • Loading branch information
dcherian committed Apr 28, 2022
2 parents b0d42d2 + e0cc051 commit e8ec1b2
Show file tree
Hide file tree
Showing 10 changed files with 150 additions and 63 deletions.
52 changes: 48 additions & 4 deletions .github/workflows/ci-additional.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ jobs:
with:
keyword: "[skip-ci]"

# This job is deprecated and can be removed soon. It's still here in case the
# move consolidate with `ci.yaml` missed something which the existing test
# picks up.
test:
name: ${{ matrix.os }} ${{ matrix.env }}
runs-on: ${{ matrix.os }}
Expand All @@ -42,8 +45,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest"]
env:
[
env: [
# Minimum python version:
"py38-bare-minimum",
"py38-min-all-deps",
Expand All @@ -67,12 +69,12 @@ jobs:
else
echo "CONDA_ENV_FILE=ci/requirements/${{ matrix.env }}.yml" >> $GITHUB_ENV
fi
- name: Cache conda
uses: actions/cache@v3
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ matrix.env }}-${{
key: ${{ runner.os }}-conda-${{ matrix.env }}-${{
hashFiles('ci/requirements/**.yml') }}

- uses: conda-incubator/setup-miniconda@v2
Expand Down Expand Up @@ -119,6 +121,7 @@ jobs:
doctest:
name: Doctests
runs-on: "ubuntu-latest"
needs: detect-ci-trigger
if: needs.detect-ci-trigger.outputs.triggered == 'false'
defaults:
run:
Expand Down Expand Up @@ -152,6 +155,47 @@ jobs:
run: |
python -m pytest --doctest-modules xarray --ignore xarray/tests
mypy:
name: Mypy
runs-on: "ubuntu-latest"
needs: detect-ci-trigger
if: needs.detect-ci-trigger.outputs.triggered == 'false'
defaults:
run:
shell: bash -l {0}

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Fetch all history for all branches and tags.
- uses: conda-incubator/setup-miniconda@v2
with:
channels: conda-forge
channel-priority: strict
mamba-version: "*"
activate-environment: xarray-tests
auto-update-conda: false
python-version: "3.9"

- name: Install conda dependencies
run: |
mamba env update -f ci/requirements/environment.yml
- name: Install xarray
run: |
python -m pip install --no-deps -e .
- name: Version info
run: |
conda info -a
conda list
python xarray/util/print_versions.py
- name: Install mypy
run: |
python -m pip install mypy
python -m mypy --install-types --non-interactive
- name: Run mypy
run: python -m mypy

min-version-policy:
name: Minimum Version Policy
runs-on: "ubuntu-latest"
Expand Down
48 changes: 47 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,21 @@ jobs:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
# Bookend python versions
python-version: ["3.8", "3.10"]
include:
# Minimum python version:
- env: "py38-bare-minimum"
python-version: 3.8
os: ubuntu-latest
- env: "py38-min-all-deps"
python-version: 3.8
os: ubuntu-latest
# Latest python version:
- env: "py39-all-but-dask"
python-version: 3.9
os: ubuntu-latest
- env: "py39-flaky"
python-version: 3.9
os: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -52,18 +67,30 @@ jobs:
if [[ ${{ matrix.os }} == windows* ]] ;
then
echo "CONDA_ENV_FILE=ci/requirements/environment-windows.yml" >> $GITHUB_ENV
elif [[ "${{ matrix.env }}" != "" ]] ;
then
if [[ "${{ matrix.env }}" == "py39-flaky" ]] ;
then
echo "CONDA_ENV_FILE=ci/requirements/environment.yml" >> $GITHUB_ENV
echo "PYTEST_EXTRA_FLAGS=--run-flaky --run-network-tests" >> $GITHUB_ENV
else
echo "CONDA_ENV_FILE=ci/requirements/${{ matrix.env }}.yml" >> $GITHUB_ENV
fi
else
echo "CONDA_ENV_FILE=ci/requirements/environment.yml" >> $GITHUB_ENV
fi
echo "PYTHON_VERSION=${{ matrix.python-version }}" >> $GITHUB_ENV
# This and the next few are based on https://github.com/conda-incubator/setup-miniconda#caching-environments
- name: Cache conda
id: cache-conda
uses: actions/cache@v3
with:
path: ~/conda_pkgs_dir
key: ${{ runner.os }}-conda-py${{ matrix.python-version }}-${{
hashFiles('ci/requirements/**.yml') }}

- uses: conda-incubator/setup-miniconda@v2
with:
channels: conda-forge
Expand All @@ -74,9 +101,25 @@ jobs:
python-version: ${{ matrix.python-version }}
use-only-tar-bz2: true

- name: Cache conda env
id: cache-env
uses: actions/cache@v3
with:
path: /usr/share/miniconda/envs/xarray-tests
key: ${{ runner.os }}-conda-py${{ matrix.python-version }}-${{
hashFiles('ci/requirements/**.yml') }}

- name: Install conda dependencies
run: |
mamba env update -f $CONDA_ENV_FILE
if: steps.cache-env.outputs.cache-hit != 'true'

# We only want to install this on one run, because otherwise we'll have
# duplicate annotations.
- name: Install error reporter
if: ${{ matrix.os }} == 'ubuntu-latest' and ${{ matrix.python-version }} == '3.10'
run: |
python -m pip install pytest-github-actions-annotate-failures
- name: Install xarray
run: |
Expand All @@ -87,14 +130,17 @@ jobs:
conda info -a
conda list
python xarray/util/print_versions.py
- name: Import xarray
run: |
python -c "import xarray"
- name: Run tests
run: python -m pytest -n 4
--cov=xarray
--cov-report=xml
--junitxml=pytest.xml
$PYTEST_EXTRA_FLAGS

- name: Upload test results
if: always()
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ released as open source in May 2014. The project was renamed from
"xray" in January 2016. Xarray became a fiscally sponsored project of
[NumFOCUS](https://numfocus.org) in August 2018.

## Contributors

Thanks to our many contributors!

[![Contributors](https://contrib.rocks/image?repo=pydata/xarray)](https://github.com/pydata/xarray/graphs/contributors)

## License

Copyright 2014-2019, xarray Developers
Expand Down
1 change: 0 additions & 1 deletion ci/requirements/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ dependencies:
- pytest
- pytest-cov
- pytest-env
- pytest-github-actions-annotate-failures
- pytest-xdist
- rasterio
- scipy
Expand Down
5 changes: 3 additions & 2 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,8 @@ def chunk(
chunks = {}

if isinstance(chunks, (float, str, int)):
chunks = dict.fromkeys(self.dims, chunks)
# ignoring type; unclear why it won't accept a Literal into the value.
chunks = dict.fromkeys(self.dims, chunks) # type: ignore
elif isinstance(chunks, (tuple, list)):
chunks = dict(zip(self.dims, chunks))
else:
Expand Down Expand Up @@ -4735,7 +4736,7 @@ def curvefit(

def drop_duplicates(
self,
dim: Hashable | Iterable[Hashable] | ...,
dim: Hashable | Iterable[Hashable],
keep: Literal["first", "last"] | Literal[False] = "first",
):
"""Returns a new DataArray with duplicate dimension values removed.
Expand Down
6 changes: 4 additions & 2 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7981,7 +7981,7 @@ def _wrapper(Y, *coords_, **kwargs):

def drop_duplicates(
self,
dim: Hashable | Iterable[Hashable] | ...,
dim: Hashable | Iterable[Hashable],
keep: Literal["first", "last"] | Literal[False] = "first",
):
"""Returns a new Dataset with duplicate dimension values removed.
Expand All @@ -8005,9 +8005,11 @@ def drop_duplicates(
DataArray.drop_duplicates
"""
if isinstance(dim, str):
dims = (dim,)
dims: Iterable = (dim,)
elif dim is ...:
dims = self.dims
elif not isinstance(dim, Iterable):
dims = [dim]
else:
dims = dim

Expand Down
Loading

0 comments on commit e8ec1b2

Please sign in to comment.