Skip to content

Commit 5332a86

Browse files
authored
fix auto_complex for open_datatree (#10632)
* fix ``auto_complex`` for ``open_datatree`` * add TestNetCDF4DataTree test class * add whats-new.rst entry * prevent TestNetCDF4Data to be collected in test_backends_datatree.py * catch ValueError for test_child_group_with_inconsistent_dimensions when run on DataTree * fix whats-new.rst * move internal changes to correct section
1 parent 4d05aa8 commit 5332a86

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

doc/whats-new.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Deprecations
2424

2525
Bug fixes
2626
~~~~~~~~~
27+
- Fix distribution of ``auto_complex`` keyword argument for open_datatree (:issue:`10631`, :pull:`10632`).
28+
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
2729

2830

2931
Documentation
@@ -32,6 +34,9 @@ Documentation
3234

3335
Internal Changes
3436
~~~~~~~~~~~~~~~~
37+
- Run ``TestNetCDF4Data`` as ``TestNetCDF4DataTree`` through ``open_datatree`` (:pull:`10632`).
38+
By `Kai Mühlbauer <https://github.com/kmuehlbauer>`_.
39+
3540

3641
.. _whats-new.2025.08.0:
3742

xarray/backends/netCDF4_.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ def open_datatree(
730730
clobber=clobber,
731731
diskless=diskless,
732732
persist=persist,
733+
auto_complex=auto_complex,
733734
lock=lock,
734735
autoclose=autoclose,
735736
**kwargs,
@@ -769,6 +770,7 @@ def open_groups_as_dict(
769770
clobber=clobber,
770771
diskless=diskless,
771772
persist=persist,
773+
auto_complex=auto_complex,
772774
lock=lock,
773775
autoclose=autoclose,
774776
)

xarray/tests/test_backends_datatree.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
requires_pydap,
2424
requires_zarr,
2525
)
26+
from xarray.tests.test_backends import TestNetCDF4Data as _TestNetCDF4Data
2627

2728
if TYPE_CHECKING:
2829
from xarray.core.datatree_io import T_DataTreeNetcdfEngine
@@ -31,6 +32,19 @@
3132
import netCDF4 as nc4
3233

3334

35+
class TestNetCDF4DataTree(_TestNetCDF4Data):
36+
@contextlib.contextmanager
37+
def open(self, path, **kwargs):
38+
with open_datatree(path, engine=self.engine, **kwargs) as ds:
39+
yield ds.to_dataset()
40+
41+
def test_child_group_with_inconsistent_dimensions(self) -> None:
42+
with pytest.raises(
43+
ValueError, match=r"group '/child' is not aligned with its parents"
44+
):
45+
super().test_child_group_with_inconsistent_dimensions()
46+
47+
3448
def diff_chunks(
3549
comparison: dict[tuple[str, Hashable], bool], tree1: DataTree, tree2: DataTree
3650
) -> str:

0 commit comments

Comments
 (0)