Skip to content
forked from pydata/xarray

Commit c8c27f7

Browse files
committed
Merge branch 'main' into groupby-dask
* main: (63 commits) Add close() method to DataTree and use it to clean-up open files in tests (pydata#9651) Change URL for pydap test (pydata#9655) Fix multiple grouping with missing groups (pydata#9650) flox: Properly propagate multiindex (pydata#9649) Update Datatree html repr to indicate inheritance (pydata#9633) Re-implement map_over_datasets using group_subtrees (pydata#9636) fix zarr intersphinx (pydata#9652) Replace black and blackdoc with ruff-format (pydata#9506) Fix error and missing code cell in io.rst (pydata#9641) Support alternative names for the root node in DataTree.from_dict (pydata#9638) Updates to DataTree.equals and DataTree.identical (pydata#9627) DOC: Clarify error message in open_dataarray (pydata#9637) Add zip_subtrees for paired iteration over DataTrees (pydata#9623) Type check datatree tests (pydata#9632) Add missing `memo` argument to DataTree.__deepcopy__ (pydata#9631) Bug fixes for DataTree indexing and aggregation (pydata#9626) Add inherit=False option to DataTree.copy() (pydata#9628) docs(groupby): mention deprecation of `squeeze` kwarg (pydata#9625) Migration guide for users of old datatree repo (pydata#9598) Reimplement Datatree typed ops (pydata#9619) ...
2 parents a15b04d + 863184d commit c8c27f7

File tree

96 files changed

+5277
-2292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+5277
-2292
lines changed

.github/FUNDING.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
github: numfocus
2-
custom: http://numfocus.org/donate-to-xarray
2+
custom: https://numfocus.org/donate-to-xarray

.github/workflows/benchmarks-last-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
fetch-depth: 0
2323

2424
- name: Set up conda environment
25-
uses: mamba-org/setup-micromamba@v1
25+
uses: mamba-org/setup-micromamba@v2
2626
with:
2727
environment-file: ${{env.CONDA_ENV_FILE}}
2828
environment-name: xarray-tests

.github/workflows/benchmarks.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
fetch-depth: 0
2626

2727
- name: Set up conda environment
28-
uses: mamba-org/setup-micromamba@v1
28+
uses: mamba-org/setup-micromamba@v2
2929
with:
3030
environment-file: ${{env.CONDA_ENV_FILE}}
3131
environment-name: xarray-tests

.github/workflows/ci-additional.yaml

+12-12
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
5656
5757
- name: Setup micromamba
58-
uses: mamba-org/setup-micromamba@v1
58+
uses: mamba-org/setup-micromamba@v2
5959
with:
6060
environment-file: ${{env.CONDA_ENV_FILE}}
6161
environment-name: xarray-tests
@@ -103,7 +103,7 @@ jobs:
103103
run: |
104104
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
105105
- name: Setup micromamba
106-
uses: mamba-org/setup-micromamba@v1
106+
uses: mamba-org/setup-micromamba@v2
107107
with:
108108
environment-file: ${{env.CONDA_ENV_FILE}}
109109
environment-name: xarray-tests
@@ -122,14 +122,14 @@ jobs:
122122
python xarray/util/print_versions.py
123123
- name: Install mypy
124124
run: |
125-
python -m pip install "mypy" --force-reinstall
125+
python -m pip install "mypy==1.11.2" --force-reinstall
126126
127127
- name: Run mypy
128128
run: |
129129
python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report
130130
131131
- name: Upload mypy coverage to Codecov
132-
uses: codecov/codecov-action@v4.5.0
132+
uses: codecov/codecov-action@v4.6.0
133133
with:
134134
file: mypy_report/cobertura.xml
135135
flags: mypy
@@ -157,7 +157,7 @@ jobs:
157157
run: |
158158
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
159159
- name: Setup micromamba
160-
uses: mamba-org/setup-micromamba@v1
160+
uses: mamba-org/setup-micromamba@v2
161161
with:
162162
environment-file: ${{env.CONDA_ENV_FILE}}
163163
environment-name: xarray-tests
@@ -176,14 +176,14 @@ jobs:
176176
python xarray/util/print_versions.py
177177
- name: Install mypy
178178
run: |
179-
python -m pip install "mypy" --force-reinstall
179+
python -m pip install "mypy==1.11.2" --force-reinstall
180180
181181
- name: Run mypy
182182
run: |
183183
python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report
184184
185185
- name: Upload mypy coverage to Codecov
186-
uses: codecov/codecov-action@v4.5.0
186+
uses: codecov/codecov-action@v4.6.0
187187
with:
188188
file: mypy_report/cobertura.xml
189189
flags: mypy-min
@@ -216,7 +216,7 @@ jobs:
216216
run: |
217217
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
218218
- name: Setup micromamba
219-
uses: mamba-org/setup-micromamba@v1
219+
uses: mamba-org/setup-micromamba@v2
220220
with:
221221
environment-file: ${{env.CONDA_ENV_FILE}}
222222
environment-name: xarray-tests
@@ -242,7 +242,7 @@ jobs:
242242
python -m pyright xarray/
243243
244244
- name: Upload pyright coverage to Codecov
245-
uses: codecov/codecov-action@v4.5.0
245+
uses: codecov/codecov-action@v4.6.0
246246
with:
247247
file: pyright_report/cobertura.xml
248248
flags: pyright
@@ -275,7 +275,7 @@ jobs:
275275
run: |
276276
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
277277
- name: Setup micromamba
278-
uses: mamba-org/setup-micromamba@v1
278+
uses: mamba-org/setup-micromamba@v2
279279
with:
280280
environment-file: ${{env.CONDA_ENV_FILE}}
281281
environment-name: xarray-tests
@@ -301,7 +301,7 @@ jobs:
301301
python -m pyright xarray/
302302
303303
- name: Upload pyright coverage to Codecov
304-
uses: codecov/codecov-action@v4.5.0
304+
uses: codecov/codecov-action@v4.6.0
305305
with:
306306
file: pyright_report/cobertura.xml
307307
flags: pyright39
@@ -324,7 +324,7 @@ jobs:
324324
fetch-depth: 0 # Fetch all history for all branches and tags.
325325

326326
- name: Setup micromamba
327-
uses: mamba-org/setup-micromamba@v1
327+
uses: mamba-org/setup-micromamba@v2
328328
with:
329329
environment-name: xarray-tests
330330
create-args: >-

.github/workflows/ci.yaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ jobs:
5858
python-version: "3.10"
5959
os: ubuntu-latest
6060
# Latest python version:
61+
- env: "all-but-numba"
62+
python-version: "3.12"
63+
os: ubuntu-latest
6164
- env: "all-but-dask"
6265
# Not 3.12 because of pint
6366
python-version: "3.11"
@@ -105,7 +108,7 @@ jobs:
105108
echo "PYTHON_VERSION=${{ matrix.python-version }}" >> $GITHUB_ENV
106109
107110
- name: Setup micromamba
108-
uses: mamba-org/setup-micromamba@v1
111+
uses: mamba-org/setup-micromamba@v2
109112
with:
110113
environment-file: ${{ env.CONDA_ENV_FILE }}
111114
environment-name: xarray-tests
@@ -159,7 +162,7 @@ jobs:
159162
path: pytest.xml
160163

161164
- name: Upload code coverage to Codecov
162-
uses: codecov/codecov-action@v4.5.0
165+
uses: codecov/codecov-action@v4.6.0
163166
with:
164167
file: ./coverage.xml
165168
flags: unittests

.github/workflows/hypothesis.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
echo "TODAY=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
6262
6363
- name: Setup micromamba
64-
uses: mamba-org/setup-micromamba@v1
64+
uses: mamba-org/setup-micromamba@v2
6565
with:
6666
environment-file: ci/requirements/environment.yml
6767
environment-name: xarray-tests

.github/workflows/nightly-wheels.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fetch-depth: 0
1414
- uses: actions/setup-python@v5
1515
with:
16-
python-version: "3.11"
16+
python-version: "3.12"
1717

1818
- name: Install dependencies
1919
run: |
@@ -38,7 +38,7 @@ jobs:
3838
fi
3939
4040
- name: Upload wheel
41-
uses: scientific-python/upload-nightly-action@b67d7fcc0396e1128a474d1ab2b48aa94680f9fc # 0.5.0
41+
uses: scientific-python/upload-nightly-action@82396a2ed4269ba06c6b2988bb4fd568ef3c3d6b # 0.6.1
4242
with:
4343
anaconda_nightly_upload_token: ${{ secrets.ANACONDA_NIGHTLY }}
4444
artifacts_path: dist

.github/workflows/pypi-release.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
path: dist
8989
- name: Publish package to TestPyPI
9090
if: github.event_name == 'push'
91-
uses: pypa/[email protected].1
91+
uses: pypa/[email protected].3
9292
with:
9393
repository_url: https://test.pypi.org/legacy/
9494
verbose: true
@@ -111,6 +111,6 @@ jobs:
111111
name: releases
112112
path: dist
113113
- name: Publish package to PyPI
114-
uses: pypa/[email protected].1
114+
uses: pypa/[email protected].3
115115
with:
116116
verbose: true

.github/workflows/upstream-dev-ci.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
with:
6262
fetch-depth: 0 # Fetch all history for all branches and tags.
6363
- name: Set up conda environment
64-
uses: mamba-org/setup-micromamba@v1
64+
uses: mamba-org/setup-micromamba@v2
6565
with:
6666
environment-file: ci/requirements/environment.yml
6767
environment-name: xarray-tests
@@ -120,7 +120,7 @@ jobs:
120120
with:
121121
fetch-depth: 0 # Fetch all history for all branches and tags.
122122
- name: Set up conda environment
123-
uses: mamba-org/setup-micromamba@v1
123+
uses: mamba-org/setup-micromamba@v2
124124
with:
125125
environment-file: ci/requirements/environment.yml
126126
environment-name: xarray-tests
@@ -146,7 +146,7 @@ jobs:
146146
run: |
147147
python -m mypy --install-types --non-interactive --cobertura-xml-report mypy_report
148148
- name: Upload mypy coverage to Codecov
149-
uses: codecov/codecov-action@v4.5.0
149+
uses: codecov/codecov-action@v4.6.0
150150
with:
151151
file: mypy_report/cobertura.xml
152152
flags: mypy

.pre-commit-config.yaml

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ci:
44
autoupdate_commit_msg: 'Update pre-commit hooks'
55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.6.0
7+
rev: v5.0.0
88
hooks:
99
- id: trailing-whitespace
1010
- id: end-of-file-fixer
@@ -13,22 +13,17 @@ repos:
1313
- id: mixed-line-ending
1414
- repo: https://github.com/astral-sh/ruff-pre-commit
1515
# Ruff version.
16-
rev: 'v0.6.3'
16+
rev: 'v0.6.9'
1717
hooks:
18+
- id: ruff-format
1819
- id: ruff
1920
args: ["--fix", "--show-fixes"]
20-
# https://github.com/python/black#version-control-integration
21-
- repo: https://github.com/psf/black-pre-commit-mirror
22-
rev: 24.8.0
23-
hooks:
24-
- id: black-jupyter
2521
- repo: https://github.com/keewis/blackdoc
2622
rev: v0.3.9
2723
hooks:
2824
- id: blackdoc
2925
exclude: "generate_aggregations.py"
3026
additional_dependencies: ["black==24.8.0"]
31-
- id: blackdoc-autoupdate-black
3227
- repo: https://github.com/pre-commit/mirrors-mypy
3328
rev: v1.11.2
3429
hooks:

CORE_TEAM_GUIDE.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,7 @@ resources such as:
271271
[NumPy documentation guide](https://numpy.org/devdocs/dev/howto-docs.html#documentation-style)
272272
for docstring conventions.
273273
- [`pre-commit`](https://pre-commit.com) hooks for autoformatting.
274-
- [`black`](https://github.com/psf/black) autoformatting.
275-
- [`flake8`](https://github.com/PyCQA/flake8) linting.
274+
- [`ruff`](https://github.com/astral-sh/ruff) autoformatting and linting.
276275
- [python-xarray](https://stackoverflow.com/questions/tagged/python-xarray) on Stack Overflow.
277276
- [@xarray_dev](https://twitter.com/xarray_dev) on Twitter.
278277
- [xarray-dev](https://discord.gg/bsSGdwBn) discord community (normally only used for remote synchronous chat during sprints).

DATATREE_MIGRATION_GUIDE.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Migration guide for users of `xarray-contrib/datatree`
2+
3+
_15th October 2024_
4+
5+
This guide is for previous users of the prototype `datatree.DataTree` class in the `xarray-contrib/datatree repository`. That repository has now been archived, and will not be maintained. This guide is intended to help smooth your transition to using the new, updated `xarray.DataTree` class.
6+
7+
> [!IMPORTANT]
8+
> There are breaking changes! You should not expect that code written with `xarray-contrib/datatree` will work without any modifications. At the absolute minimum you will need to change the top-level import statement, but there are other changes too.
9+
10+
We have made various changes compared to the prototype version. These can be split into three categories: data model changes, which affect the hierarchal structure itself; integration with xarray's IO backends; and minor API changes, which mostly consist of renaming methods to be more self-consistent.
11+
12+
### Data model changes
13+
14+
The most important changes made are to the data model of `DataTree`. Whilst previously data in different nodes was unrelated and therefore unconstrained, now trees have "internal alignment" - meaning that dimensions and indexes in child nodes must exactly align with those in their parents.
15+
16+
These alignment checks happen at tree construction time, meaning there are some netCDF4 files and zarr stores that could previously be opened as `datatree.DataTree` objects using `datatree.open_datatree`, but now cannot be opened as `xr.DataTree` objects using `xr.open_datatree`. For these cases we added a new opener function `xr.open_groups`, which returns a `dict[str, Dataset]`. This is intended as a fallback for tricky cases, where the idea is that you can still open the entire contents of the file using `open_groups`, edit the `Dataset` objects, then construct a valid tree from the edited dictionary using `DataTree.from_dict`.
17+
18+
The alignment checks allowed us to add "Coordinate Inheritance", a much-requested feature where indexed coordinate variables are now "inherited" down to child nodes. This allows you to define common coordinates in a parent group that are then automatically available on every child node. The distinction between a locally-defined coordinate variables and an inherited coordinate that was defined on a parent node is reflected in the `DataTree.__repr__`. Generally if you prefer not to have these variables be inherited you can get more similar behaviour to the old `datatree` package by removing indexes from coordinates, as this prevents inheritance.
19+
20+
Tree structure checks between multiple trees (i.e., `DataTree.isomorophic`) and pairing of nodes in arithmetic has also changed. Nodes are now matched (with `xarray.group_subtrees`) based on their relative paths, without regard to the order in which child nodes are defined.
21+
22+
For further documentation see the page in the user guide on Hierarchical Data.
23+
24+
### Integrated backends
25+
26+
Previously `datatree.open_datatree` used a different codepath from `xarray.open_dataset`, and was hard-coded to only support opening netCDF files and Zarr stores.
27+
Now xarray's backend entrypoint system has been generalized to include `open_datatree` and the new `open_groups`.
28+
This means we can now extend other xarray backends to support `open_datatree`! If you are the maintainer of an xarray backend we encourage you to add support for `open_datatree` and `open_groups`!
29+
30+
Additionally:
31+
- A `group` kwarg has been added to `open_datatree` for choosing which group in the file should become the root group of the created tree.
32+
- Various performance improvements have been made, which should help when opening netCDF files and Zarr stores with large numbers of groups.
33+
- We anticipate further performance improvements being possible for datatree IO.
34+
35+
### API changes
36+
37+
A number of other API changes have been made, which should only require minor modifications to your code:
38+
- The top-level import has changed, from `from datatree import DataTree, open_datatree` to `from xarray import DataTree, open_datatree`. Alternatively you can now just use the `import xarray as xr` namespace convention for everything datatree-related.
39+
- The `DataTree.ds` property has been changed to `DataTree.dataset`, though `DataTree.ds` remains as an alias for `DataTree.dataset`.
40+
- Similarly the `ds` kwarg in the `DataTree.__init__` constructor has been replaced by `dataset`, i.e. use `DataTree(dataset=)` instead of `DataTree(ds=...)`.
41+
- The method `DataTree.to_dataset()` still exists but now has different options for controlling which variables are present on the resulting `Dataset`, e.g. `inherit=True/False`.
42+
- `DataTree.copy()` also has a new `inherit` keyword argument for controlling whether or not coordinates defined on parents are copied (only relevant when copying a non-root node).
43+
- The `DataTree.parent` property is now read-only. To assign a ancestral relationships directly you must instead use the `.children` property on the parent node, which remains settable.
44+
- Similarly the `parent` kwarg has been removed from the `DataTree.__init__` constuctor.
45+
- DataTree objects passed to the `children` kwarg in `DataTree.__init__` are now shallow-copied.
46+
- `DataTree.as_array` has been replaced by `DataTree.to_dataarray`.
47+
- A number of methods which were not well tested have been (temporarily) disabled. In general we have tried to only keep things that are known to work, with the plan to increase API surface incrementally after release.
48+
49+
## Thank you!
50+
51+
Thank you for trying out `xarray-contrib/datatree`!
52+
53+
We welcome contributions of any kind, including good ideas that never quite made it into the original datatree repository. Please also let us know if we have forgotten to mention a change that should have been listed in this guide.
54+
55+
Sincerely, the datatree team:
56+
57+
Tom Nicholas,
58+
Owen Littlejohns,
59+
Matt Savoie,
60+
Eni Awowale,
61+
Alfonso Ladino,
62+
Justus Magin,
63+
Stephan Hoyer

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ Xarray is a fiscally sponsored project of
8888
[NumFOCUS](https://numfocus.org), a nonprofit dedicated to supporting
8989
the open source scientific computing community. If you like Xarray and
9090
want to support our mission, please consider making a
91-
[donation](https://numfocus.salsalabs.org/donate-to-xarray/) to support
91+
[donation](https://numfocus.org/donate-to-xarray) to support
9292
our efforts.
9393

9494
## History

ci/min_deps_check.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
publication date. Compare it against requirements/min-all-deps.yml to verify the
44
policy on obsolete dependencies is being followed. Print a pretty report :)
55
"""
6+
67
from __future__ import annotations
78

89
import itertools
@@ -16,7 +17,6 @@
1617

1718
CHANNELS = ["conda-forge", "defaults"]
1819
IGNORE_DEPS = {
19-
"black",
2020
"coveralls",
2121
"flake8",
2222
"hypothesis",

ci/requirements/all-but-dask.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ channels:
33
- conda-forge
44
- nodefaults
55
dependencies:
6-
- black
76
- aiobotocore
87
- array-api-strict
98
- boto3

0 commit comments

Comments
 (0)