Skip to content

Commit 473b87f

Browse files
owenlittlejohnsflamingbeardcherian
authored
Migrate datatree.py module into xarray.core. (#8789)
* Migrate datatree.py module into xarray.core. * Add correct PR reference to whats-new.rst. * Revert to using Union in datatree.py. * Catch remaining unfixed import path. * Fix easier mypy annotations in datatree.py and test_datatree.py. * Straggling mypy change in datatree.py. * datatree.py comment clean-up. * More mypy corrections in datatree.py and test_datatree.py. * Removes unnecessary dict wrapper. * DAS-2062: renames as_array -> to_dataarray * DAS-2062: Updates doc string for Datatree.to_zarr Accurately reflects the default value now. * DAS-2062: reverts what-new.rst for "breaking changes that aren't breaking yet but will be, but only relevant for previous users of another package" * DAS-2062: clarify wording in comment. * Change Datatree.to_dataarray to call correctly We updated the name but not the function. * Clarify DataTree's names are still strings now. DAS-2062 * DAS-2062: Cast k explicitly to str for typing. So this is where we are moving forward with the assumption that DataTree nodes are alway named with a string. In this section of `update` even though we know the key is a str, mypy refuses. I chose explicit recast over mypy ignores, tell me why that's wrong? * Ignore mypy errors for DataTree.ds assignment. * Fix DataTree.update type hint. * Final mypy issue - ignore DataTree.get override. * Update contributors in whats-new.rst * Fix GitHub handle. --------- Co-authored-by: Matt Savoie <[email protected]> Co-authored-by: Matt Savoie <[email protected]> Co-authored-by: Deepak Cherian <[email protected]>
1 parent 55173e8 commit 473b87f

23 files changed

+257
-238
lines changed

doc/whats-new.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ Internal Changes
8282
- Migrates ``treenode`` functionality into ``xarray/core`` (:pull:`8757`)
8383
By `Matt Savoie <https://github.com/flamingbear>`_ and `Tom Nicholas
8484
<https://github.com/TomNicholas>`_.
85+
- Migrates ``datatree`` functionality into ``xarray/core``. (:pull: `8789`)
86+
By `Owen Littlejohns <https://github.com/owenlittlejohns>`_, `Matt Savoie
87+
<https://github.com/flamingbear>`_ and `Tom Nicholas <https://github.com/TomNicholas>`_.
8588

8689

8790
.. _whats-new.2024.02.0:

xarray/backends/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
T_NetcdfTypes = Literal[
7070
"NETCDF4", "NETCDF4_CLASSIC", "NETCDF3_64BIT", "NETCDF3_CLASSIC"
7171
]
72-
from xarray.datatree_.datatree import DataTree
72+
from xarray.core.datatree import DataTree
7373

7474
DATAARRAY_NAME = "__xarray_dataarray_name__"
7575
DATAARRAY_VARIABLE = "__xarray_dataarray_variable__"

xarray/backends/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
from netCDF4 import Dataset as ncDataset
2424

2525
from xarray.core.dataset import Dataset
26+
from xarray.core.datatree import DataTree
2627
from xarray.core.types import NestedSequence
27-
from xarray.datatree_.datatree import DataTree
2828

2929
# Create a logger object, but don't add any handlers. Leave that to user code.
3030
logger = logging.getLogger(__name__)
@@ -137,8 +137,8 @@ def _open_datatree_netcdf(
137137
**kwargs,
138138
) -> DataTree:
139139
from xarray.backends.api import open_dataset
140+
from xarray.core.datatree import DataTree
140141
from xarray.core.treenode import NodePath
141-
from xarray.datatree_.datatree import DataTree
142142

143143
ds = open_dataset(filename_or_obj, **kwargs)
144144
tree_root = DataTree.from_dict({"/": ds})

xarray/backends/h5netcdf_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
from xarray.backends.common import AbstractDataStore
4242
from xarray.core.dataset import Dataset
43-
from xarray.datatree_.datatree import DataTree
43+
from xarray.core.datatree import DataTree
4444

4545

4646
class H5NetCDFArrayWrapper(BaseNetCDF4Array):

xarray/backends/netCDF4_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545

4646
from xarray.backends.common import AbstractDataStore
4747
from xarray.core.dataset import Dataset
48-
from xarray.datatree_.datatree import DataTree
48+
from xarray.core.datatree import DataTree
4949

5050
# This lookup table maps from dtype.byteorder to a readable endian
5151
# string used by netCDF4.

xarray/backends/zarr.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
from xarray.backends.common import AbstractDataStore
3636
from xarray.core.dataset import Dataset
37-
from xarray.datatree_.datatree import DataTree
37+
from xarray.core.datatree import DataTree
3838

3939

4040
# need some special secret attributes to tell us the dimensions
@@ -1048,8 +1048,8 @@ def open_datatree(
10481048
import zarr
10491049

10501050
from xarray.backends.api import open_dataset
1051+
from xarray.core.datatree import DataTree
10511052
from xarray.core.treenode import NodePath
1052-
from xarray.datatree_.datatree import DataTree
10531053

10541054
zds = zarr.open_group(filename_or_obj, mode="r")
10551055
ds = open_dataset(filename_or_obj, engine="zarr", **kwargs)

0 commit comments

Comments
 (0)