From fac2c89ee634ff572e6c6318c40b1b729a07cbac Mon Sep 17 00:00:00 2001 From: Stephan Hoyer Date: Tue, 10 Sep 2024 18:30:29 -0700 Subject: [PATCH] Rename DataTree's "ds" and "data" to "dataset" (#9476) * Rename DataTree's "ds" and "data" to "dataset" .ds is kept around as a soft-deprecated alias to facilitate the transition from xarray-contrib/datatree, though I verified that all tests pass without it. * fix data= usage in test_formatting_html.py * fix formatting test --- xarray/backends/zarr.py | 2 +- xarray/core/datatree.py | 66 +++++++++--------- xarray/core/datatree_mapping.py | 11 +-- xarray/core/formatting.py | 2 +- xarray/tests/test_backends_datatree.py | 4 +- xarray/tests/test_datatree.py | 92 +++++++++++++------------- xarray/tests/test_formatting.py | 8 +-- xarray/tests/test_formatting_html.py | 2 +- 8 files changed, 95 insertions(+), 92 deletions(-) diff --git a/xarray/backends/zarr.py b/xarray/backends/zarr.py index 31b367a178b..fd938238ae4 100644 --- a/xarray/backends/zarr.py +++ b/xarray/backends/zarr.py @@ -1262,7 +1262,7 @@ def open_datatree( ds = open_dataset( filename_or_obj, store=store, group=path_group, engine="zarr", **kwargs ) - new_node: DataTree = DataTree(name=NodePath(path_group).name, data=ds) + new_node = DataTree(name=NodePath(path_group).name, dataset=ds) tree_root._set_item( path_group, new_node, diff --git a/xarray/core/datatree.py b/xarray/core/datatree.py index b12d861624a..d600b18d1d6 100644 --- a/xarray/core/datatree.py +++ b/xarray/core/datatree.py @@ -417,7 +417,7 @@ class DataTree( def __init__( self, - data: Dataset | None = None, + dataset: Dataset | None = None, children: Mapping[str, DataTree] | None = None, name: str | None = None, ): @@ -430,12 +430,12 @@ def __init__( Parameters ---------- - data : Dataset, optional - Data to store under the .ds attribute of this node. + dataset : Dataset, optional + Data to store directly at this node. children : Mapping[str, DataTree], optional - Any child nodes of this node. Default is None. + Any child nodes of this node. name : str, optional - Name for this node of the tree. Default is None. + Name for this node of the tree. Returns ------- @@ -449,24 +449,24 @@ def __init__( children = {} super().__init__(name=name) - self._set_node_data(_to_new_dataset(data)) + self._set_node_data(_to_new_dataset(dataset)) # shallow copy to avoid modifying arguments in-place (see GH issue #9196) self.children = {name: child.copy() for name, child in children.items()} - def _set_node_data(self, ds: Dataset): - data_vars, coord_vars = _collect_data_and_coord_variables(ds) + def _set_node_data(self, dataset: Dataset): + data_vars, coord_vars = _collect_data_and_coord_variables(dataset) self._data_variables = data_vars self._node_coord_variables = coord_vars - self._node_dims = ds._dims - self._node_indexes = ds._indexes - self._encoding = ds._encoding - self._attrs = ds._attrs - self._close = ds._close + self._node_dims = dataset._dims + self._node_indexes = dataset._indexes + self._encoding = dataset._encoding + self._attrs = dataset._attrs + self._close = dataset._close def _pre_attach(self: DataTree, parent: DataTree, name: str) -> None: super()._pre_attach(parent, name) - if name in parent.ds.variables: + if name in parent.dataset.variables: raise KeyError( f"parent {parent.name} already contains a variable named {name}" ) @@ -534,7 +534,7 @@ def _to_dataset_view(self, rebuild_dims: bool, inherited: bool) -> DatasetView: ) @property - def ds(self) -> DatasetView: + def dataset(self) -> DatasetView: """ An immutable Dataset-like view onto the data in this node. @@ -549,11 +549,15 @@ def ds(self) -> DatasetView: """ return self._to_dataset_view(rebuild_dims=True, inherited=True) - @ds.setter - def ds(self, data: Dataset | None = None) -> None: + @dataset.setter + def dataset(self, data: Dataset | None = None) -> None: ds = _to_new_dataset(data) self._replace_node(ds) + # soft-deprecated alias, to facilitate the transition from + # xarray-contrib/datatree + ds = dataset + def to_dataset(self, inherited: bool = True) -> Dataset: """ Return the data in this node as a new xarray.Dataset object. @@ -566,7 +570,7 @@ def to_dataset(self, inherited: bool = True) -> Dataset: See Also -------- - DataTree.ds + DataTree.dataset """ coord_vars = self._coord_variables if inherited else self._node_coord_variables variables = dict(self._data_variables) @@ -845,8 +849,8 @@ def get( # type: ignore[override] """ if key in self.children: return self.children[key] - elif key in self.ds: - return self.ds[key] + elif key in self.dataset: + return self.dataset[key] else: return default @@ -1114,7 +1118,7 @@ def from_dict( if isinstance(root_data, DataTree): obj = root_data.copy() elif root_data is None or isinstance(root_data, Dataset): - obj = cls(name=name, data=root_data, children=None) + obj = cls(name=name, dataset=root_data, children=None) else: raise TypeError( f'root node data (at "/") must be a Dataset or DataTree, got {type(root_data)}' @@ -1133,7 +1137,7 @@ def depth(item) -> int: if isinstance(data, DataTree): new_node = data.copy() elif isinstance(data, Dataset) or data is None: - new_node = cls(name=node_name, data=data) + new_node = cls(name=node_name, dataset=data) else: raise TypeError(f"invalid values: {data}") obj._set_item( @@ -1264,7 +1268,7 @@ def equals(self, other: DataTree, from_root: bool = True) -> bool: return all( [ - node.ds.equals(other_node.ds) + node.dataset.equals(other_node.dataset) for node, other_node in zip(self.subtree, other.subtree, strict=True) ] ) @@ -1294,7 +1298,7 @@ def identical(self, other: DataTree, from_root=True) -> bool: return False return all( - node.ds.identical(other_node.ds) + node.dataset.identical(other_node.dataset) for node, other_node in zip(self.subtree, other.subtree, strict=True) ) @@ -1321,7 +1325,7 @@ def filter(self: DataTree, filterfunc: Callable[[DataTree], bool]) -> DataTree: map_over_subtree """ filtered_nodes = { - node.path: node.ds for node in self.subtree if filterfunc(node) + node.path: node.dataset for node in self.subtree if filterfunc(node) } return DataTree.from_dict(filtered_nodes, name=self.root.name) @@ -1365,7 +1369,7 @@ def match(self, pattern: str) -> DataTree: └── Group: /b/B """ matching_nodes = { - node.path: node.ds + node.path: node.dataset for node in self.subtree if NodePath(node.path).match(pattern) } @@ -1389,7 +1393,7 @@ def map_over_subtree( ---------- func : callable Function to apply to datasets with signature: - `func(node.ds, *args, **kwargs) -> Dataset`. + `func(node.dataset, *args, **kwargs) -> Dataset`. Function will not be applied to any nodes without datasets. *args : tuple, optional @@ -1420,7 +1424,7 @@ def map_over_subtree_inplace( ---------- func : callable Function to apply to datasets with signature: - `func(node.ds, *args, **kwargs) -> Dataset`. + `func(node.dataset, *args, **kwargs) -> Dataset`. Function will not be applied to any nodes without datasets, *args : tuple, optional @@ -1433,7 +1437,7 @@ def map_over_subtree_inplace( for node in self.subtree: if node.has_data: - node.ds = func(node.ds, *args, **kwargs) + node.dataset = func(node.dataset, *args, **kwargs) def pipe( self, func: Callable | tuple[Callable, str], *args: Any, **kwargs: Any @@ -1499,7 +1503,7 @@ def render(self): """Print tree structure, including any data stored at each node.""" for pre, fill, node in RenderDataTree(self): print(f"{pre}DataTree('{self.name}')") - for ds_line in repr(node.ds)[1:]: + for ds_line in repr(node.dataset)[1:]: print(f"{fill}{ds_line}") def merge(self, datatree: DataTree) -> DataTree: @@ -1513,7 +1517,7 @@ def merge_child_nodes(self, *paths, new_path: T_Path) -> DataTree: # TODO some kind of .collapse() or .flatten() method to merge a subtree def to_dataarray(self) -> DataArray: - return self.ds.to_dataarray() + return self.dataset.to_dataarray() @property def groups(self): diff --git a/xarray/core/datatree_mapping.py b/xarray/core/datatree_mapping.py index 1a581629ab8..78abf42601d 100644 --- a/xarray/core/datatree_mapping.py +++ b/xarray/core/datatree_mapping.py @@ -99,10 +99,10 @@ def map_over_subtree(func: Callable) -> Callable: Function will not be applied to any nodes without datasets. *args : tuple, optional Positional arguments passed on to `func`. If DataTrees any data-containing nodes will be converted to Datasets - via `.ds`. + via `.dataset`. **kwargs : Any Keyword arguments passed on to `func`. If DataTrees any data-containing nodes will be converted to Datasets - via `.ds`. + via `.dataset`. Returns ------- @@ -160,13 +160,14 @@ def _map_over_subtree(*args, **kwargs) -> DataTree | tuple[DataTree, ...]: strict=False, ): node_args_as_datasetviews = [ - a.ds if isinstance(a, DataTree) else a for a in all_node_args[:n_args] + a.dataset if isinstance(a, DataTree) else a + for a in all_node_args[:n_args] ] node_kwargs_as_datasetviews = dict( zip( [k for k in kwargs_as_tree_length_iterables.keys()], [ - v.ds if isinstance(v, DataTree) else v + v.dataset if isinstance(v, DataTree) else v for v in all_node_args[n_args:] ], strict=True, @@ -183,7 +184,7 @@ def _map_over_subtree(*args, **kwargs) -> DataTree | tuple[DataTree, ...]: ) elif node_of_first_tree.has_attrs: # propagate attrs - results = node_of_first_tree.ds + results = node_of_first_tree.dataset else: # nothing to propagate so use fastpath to create empty node in new tree results = None diff --git a/xarray/core/formatting.py b/xarray/core/formatting.py index d17a72aac27..1cea9a7a28d 100644 --- a/xarray/core/formatting.py +++ b/xarray/core/formatting.py @@ -1038,7 +1038,7 @@ def diff_nodewise_summary(a: DataTree, b: DataTree, compat): summary = [] for node_a, node_b in zip(a.subtree, b.subtree, strict=True): - a_ds, b_ds = node_a.ds, node_b.ds + a_ds, b_ds = node_a.dataset, node_b.dataset if not a_ds._all_compat(b_ds, compat): dataset_diff = diff_dataset_repr(a_ds, b_ds, compat_str) diff --git a/xarray/tests/test_backends_datatree.py b/xarray/tests/test_backends_datatree.py index e84c77e54ed..d9490385b7d 100644 --- a/xarray/tests/test_backends_datatree.py +++ b/xarray/tests/test_backends_datatree.py @@ -56,7 +56,7 @@ def test_netcdf_encoding(self, tmpdir, simple_datatree): # add compression comp = dict(zlib=True, complevel=9) - enc = {"/set2": {var: comp for var in original_dt["/set2"].ds.data_vars}} + enc = {"/set2": {var: comp for var in original_dt["/set2"].dataset.data_vars}} original_dt.to_netcdf(filepath, encoding=enc, engine=self.engine) roundtrip_dt = open_datatree(filepath, engine=self.engine) @@ -246,7 +246,7 @@ def test_zarr_encoding(self, tmpdir, simple_datatree): original_dt = simple_datatree comp = {"compressor": zarr.Blosc(cname="zstd", clevel=3, shuffle=2)} - enc = {"/set2": {var: comp for var in original_dt["/set2"].ds.data_vars}} + enc = {"/set2": {var: comp for var in original_dt["/set2"].dataset.data_vars}} original_dt.to_zarr(filepath, encoding=enc) roundtrip_dt = open_datatree(filepath, engine="zarr") diff --git a/xarray/tests/test_datatree.py b/xarray/tests/test_datatree.py index 353f1fab708..e6eb4c8dd22 100644 --- a/xarray/tests/test_datatree.py +++ b/xarray/tests/test_datatree.py @@ -36,11 +36,11 @@ def test_bad_names(self): def test_data_arg(self): ds = xr.Dataset({"foo": 42}) - tree: DataTree = DataTree(data=ds) + tree: DataTree = DataTree(dataset=ds) assert_identical(tree.to_dataset(), ds) with pytest.raises(TypeError): - DataTree(data=xr.DataArray(42, name="foo")) # type: ignore[arg-type] + DataTree(dataset=xr.DataArray(42, name="foo")) # type: ignore[arg-type] class TestFamilyTree: @@ -141,38 +141,38 @@ def test_relative_paths(self): class TestStoreDatasets: def test_create_with_data(self): dat = xr.Dataset({"a": 0}) - john = DataTree(name="john", data=dat) + john = DataTree(name="john", dataset=dat) assert_identical(john.to_dataset(), dat) with pytest.raises(TypeError): - DataTree(name="mary", data="junk") # type: ignore[arg-type] + DataTree(name="mary", dataset="junk") # type: ignore[arg-type] def test_set_data(self): john = DataTree(name="john") dat = xr.Dataset({"a": 0}) - john.ds = dat # type: ignore[assignment] + john.dataset = dat # type: ignore[assignment] assert_identical(john.to_dataset(), dat) with pytest.raises(TypeError): - john.ds = "junk" # type: ignore[assignment] + john.dataset = "junk" # type: ignore[assignment] def test_has_data(self): - john = DataTree(name="john", data=xr.Dataset({"a": 0})) + john = DataTree(name="john", dataset=xr.Dataset({"a": 0})) assert john.has_data - john_no_data = DataTree(name="john", data=None) + john_no_data = DataTree(name="john", dataset=None) assert not john_no_data.has_data def test_is_hollow(self): - john = DataTree(data=xr.Dataset({"a": 0})) + john = DataTree(dataset=xr.Dataset({"a": 0})) assert john.is_hollow eve = DataTree(children={"john": john}) assert eve.is_hollow - eve.ds = xr.Dataset({"a": 1}) # type: ignore[assignment] + eve.dataset = xr.Dataset({"a": 1}) # type: ignore[assignment] assert not eve.is_hollow @@ -197,7 +197,7 @@ def test_parent_already_has_variable_with_childs_name(self): DataTree.from_dict({"/": xr.Dataset({"a": [0], "b": 1}), "/a": None}) def test_parent_already_has_variable_with_childs_name_update(self): - dt = DataTree(data=xr.Dataset({"a": [0], "b": 1})) + dt = DataTree(dataset=xr.Dataset({"a": [0], "b": 1})) with pytest.raises(ValueError, match="already contains a variable named a"): dt.update({"a": DataTree()}) @@ -209,13 +209,13 @@ def test_assign_when_already_child_with_variables_name(self): ) with pytest.raises(ValueError, match="node already contains a variable"): - dt.ds = xr.Dataset({"a": 0}) # type: ignore[assignment] + dt.dataset = xr.Dataset({"a": 0}) # type: ignore[assignment] - dt.ds = xr.Dataset() # type: ignore[assignment] + dt.dataset = xr.Dataset() # type: ignore[assignment] new_ds = dt.to_dataset().assign(a=xr.DataArray(0)) with pytest.raises(ValueError, match="node already contains a variable"): - dt.ds = new_ds # type: ignore[assignment] + dt.dataset = new_ds # type: ignore[assignment] class TestGet: ... @@ -238,7 +238,7 @@ def test_getitem_self(self): def test_getitem_single_data_variable(self): data = xr.Dataset({"temp": [0, 50]}) - results = DataTree(name="results", data=data) + results = DataTree(name="results", dataset=data) assert_identical(results["temp"], data["temp"]) def test_getitem_single_data_variable_from_node(self): @@ -257,14 +257,14 @@ def test_getitem_nonexistent_node(self): def test_getitem_nonexistent_variable(self): data = xr.Dataset({"temp": [0, 50]}) - results = DataTree(name="results", data=data) + results = DataTree(name="results", dataset=data) with pytest.raises(KeyError): results["pressure"] @pytest.mark.xfail(reason="Should be deprecated in favour of .subset") def test_getitem_multiple_data_variables(self): data = xr.Dataset({"temp": [0, 50], "p": [5, 8, 7]}) - results = DataTree(name="results", data=data) + results = DataTree(name="results", dataset=data) assert_identical(results[["temp", "p"]], data[["temp", "p"]]) # type: ignore[index] @pytest.mark.xfail( @@ -272,7 +272,7 @@ def test_getitem_multiple_data_variables(self): ) def test_getitem_dict_like_selection_access_to_dataset(self): data = xr.Dataset({"temp": [0, 50]}) - results = DataTree(name="results", data=data) + results = DataTree(name="results", dataset=data) assert_identical(results[{"temp": 1}], data[{"temp": 1}]) # type: ignore[index] @@ -440,7 +440,7 @@ def test_setitem_unnamed_child_node_becomes_named(self): def test_setitem_new_grandchild_node(self): john = DataTree.from_dict({"/Mary/Rose": DataTree()}) - new_rose = DataTree(data=xr.Dataset({"x": 0})) + new_rose = DataTree(dataset=xr.Dataset({"x": 0})) john["Mary/Rose"] = new_rose grafted_rose = john["Mary/Rose"] @@ -466,7 +466,7 @@ def test_setitem_overwrite_data_in_node_with_none(self): john["mary"] = DataTree() assert_identical(john["mary"].to_dataset(), xr.Dataset()) - john.ds = xr.Dataset() # type: ignore[assignment] + john.dataset = xr.Dataset() # type: ignore[assignment] with pytest.raises(ValueError, match="has no name"): john["."] = DataTree() @@ -518,20 +518,20 @@ def test_setitem_coerce_to_dataarray(self): def test_setitem_add_new_variable_to_empty_node(self): results = DataTree(name="results") results["pressure"] = xr.DataArray(data=[2, 3]) - assert "pressure" in results.ds + assert "pressure" in results.dataset results["temp"] = xr.Variable(data=[10, 11], dims=["x"]) - assert "temp" in results.ds + assert "temp" in results.dataset # What if there is a path to traverse first? results_with_path = DataTree(name="results") results_with_path["highres/pressure"] = xr.DataArray(data=[2, 3]) - assert "pressure" in results_with_path["highres"].ds + assert "pressure" in results_with_path["highres"].dataset results_with_path["highres/temp"] = xr.Variable(data=[10, 11], dims=["x"]) - assert "temp" in results_with_path["highres"].ds + assert "temp" in results_with_path["highres"].dataset def test_setitem_dataarray_replace_existing_node(self): t = xr.Dataset({"temp": [0, 50]}) - results = DataTree(name="results", data=t) + results = DataTree(name="results", dataset=t) p = xr.DataArray(data=[2, 3]) results["pressure"] = p expected = t.assign(pressure=p) @@ -620,7 +620,7 @@ def test_full(self, simple_datatree): ] def test_datatree_values(self): - dat1 = DataTree(data=xr.Dataset({"a": 1})) + dat1 = DataTree(dataset=xr.Dataset({"a": 1})) expected = DataTree() expected["a"] = dat1 @@ -675,11 +675,11 @@ def test_array_values(self): class TestDatasetView: def test_view_contents(self): ds = create_test_data() - dt = DataTree(data=ds) + dt = DataTree(dataset=ds) assert ds.identical( - dt.ds + dt.dataset ) # this only works because Dataset.identical doesn't check types - assert isinstance(dt.ds, xr.Dataset) + assert isinstance(dt.dataset, xr.Dataset) def test_immutability(self): # See issue https://github.com/xarray-contrib/datatree/issues/38 @@ -694,28 +694,28 @@ def test_immutability(self): with pytest.raises( AttributeError, match="Mutation of the DatasetView is not allowed" ): - dt.ds["a"] = xr.DataArray(0) + dt.dataset["a"] = xr.DataArray(0) with pytest.raises( AttributeError, match="Mutation of the DatasetView is not allowed" ): - dt.ds.update({"a": 0}) + dt.dataset.update({"a": 0}) # TODO are there any other ways you can normally modify state (in-place)? # (not attribute-like assignment because that doesn't work on Dataset anyway) def test_methods(self): ds = create_test_data() - dt = DataTree(data=ds) - assert ds.mean().identical(dt.ds.mean()) - assert isinstance(dt.ds.mean(), xr.Dataset) + dt = DataTree(dataset=ds) + assert ds.mean().identical(dt.dataset.mean()) + assert isinstance(dt.dataset.mean(), xr.Dataset) def test_arithmetic(self, create_test_datatree): dt = create_test_datatree() expected = create_test_datatree(modify=lambda ds: 10.0 * ds)[ "set1" ].to_dataset() - result = 10.0 * dt["set1"].ds + result = 10.0 * dt["set1"].dataset assert result.identical(expected) def test_init_via_type(self): @@ -727,12 +727,12 @@ def test_init_via_type(self): dims=["x", "y", "time"], coords={"area": (["x", "y"], np.random.rand(3, 4))}, ).to_dataset(name="data") - dt = DataTree(data=a) + dt = DataTree(dataset=a) def weighted_mean(ds): return ds.weighted(ds.area).mean(["x", "y"]) - weighted_mean(dt.ds) + weighted_mean(dt.dataset) class TestAccess: @@ -961,7 +961,7 @@ def test_inherited_dims(self): assert dt.b.sizes == {"x": 2, "y": 1} assert dt.c.sizes == {"x": 2, "y": 3} # dataset objects created from nodes should not - assert dt.b.ds.sizes == {"y": 1} + assert dt.b.dataset.sizes == {"y": 1} assert dt.b.to_dataset(inherited=True).sizes == {"y": 1} assert dt.b.to_dataset(inherited=False).sizes == {"y": 1} @@ -1021,10 +1021,10 @@ def test_inconsistent_dims(self): with pytest.raises(ValueError, match=expected_msg): dt["/b/c"] = xr.DataArray([3.0], dims=["x"]) - b = DataTree(data=xr.Dataset({"c": (("x",), [3.0])})) + b = DataTree(dataset=xr.Dataset({"c": (("x",), [3.0])})) with pytest.raises(ValueError, match=expected_msg): DataTree( - data=xr.Dataset({"a": (("x",), [1.0, 2.0])}), + dataset=xr.Dataset({"a": (("x",), [1.0, 2.0])}), children={"b": b}, ) @@ -1054,14 +1054,14 @@ def test_inconsistent_child_indexes(self): ) dt = DataTree() - dt.ds = xr.Dataset(coords={"x": [1.0]}) # type: ignore[assignment] + dt.dataset = xr.Dataset(coords={"x": [1.0]}) # type: ignore[assignment] dt["/b"] = DataTree() with pytest.raises(ValueError, match=expected_msg): - dt["/b"].ds = xr.Dataset(coords={"x": [2.0]}) + dt["/b"].dataset = xr.Dataset(coords={"x": [2.0]}) b = DataTree(xr.Dataset(coords={"x": [2.0]})) with pytest.raises(ValueError, match=expected_msg): - DataTree(data=xr.Dataset(coords={"x": [1.0]}), children={"b": b}) + DataTree(dataset=xr.Dataset(coords={"x": [1.0]}), children={"b": b}) def test_inconsistent_grandchild_indexes(self): expected_msg = _exact_match( @@ -1089,15 +1089,15 @@ def test_inconsistent_grandchild_indexes(self): ) dt = DataTree() - dt.ds = xr.Dataset(coords={"x": [1.0]}) # type: ignore[assignment] + dt.dataset = xr.Dataset(coords={"x": [1.0]}) # type: ignore[assignment] dt["/b/c"] = DataTree() with pytest.raises(ValueError, match=expected_msg): - dt["/b/c"].ds = xr.Dataset(coords={"x": [2.0]}) + dt["/b/c"].dataset = xr.Dataset(coords={"x": [2.0]}) c = DataTree(xr.Dataset(coords={"x": [2.0]})) b = DataTree(children={"c": c}) with pytest.raises(ValueError, match=expected_msg): - DataTree(data=xr.Dataset(coords={"x": [1.0]}), children={"b": b}) + DataTree(dataset=xr.Dataset(coords={"x": [1.0]}), children={"b": b}) def test_inconsistent_grandchild_dims(self): expected_msg = _exact_match( diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index 6066eeacfee..2e48b3a4219 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -626,7 +626,7 @@ def test_datatree_print_empty_node(self): def test_datatree_print_empty_node_with_attrs(self): dat = xr.Dataset(attrs={"note": "has attrs"}) - dt: DataTree = DataTree(name="root", data=dat) + dt: DataTree = DataTree(name="root", dataset=dat) printout = str(dt) assert printout == dedent( """\ @@ -638,7 +638,7 @@ def test_datatree_print_empty_node_with_attrs(self): def test_datatree_print_node_with_data(self): dat = xr.Dataset({"a": [0, 2]}) - dt: DataTree = DataTree(name="root", data=dat) + dt: DataTree = DataTree(name="root", dataset=dat) printout = str(dt) expected = [ "", @@ -646,8 +646,6 @@ def test_datatree_print_node_with_data(self): "Dimensions", "Coordinates", "a", - "Data variables", - "*empty*", ] for expected_line, printed_line in zip( expected, printout.splitlines(), strict=True @@ -666,7 +664,7 @@ def test_datatree_printout_nested_node(self): def test_datatree_repr_of_node_with_data(self): dat = xr.Dataset({"a": [0, 2]}) - dt: DataTree = DataTree(name="root", data=dat) + dt: DataTree = DataTree(name="root", dataset=dat) assert "Coordinates" in repr(dt) def test_diff_datatree_repr_structure(self): diff --git a/xarray/tests/test_formatting_html.py b/xarray/tests/test_formatting_html.py index ada7f75b21b..e1f51e38882 100644 --- a/xarray/tests/test_formatting_html.py +++ b/xarray/tests/test_formatting_html.py @@ -220,7 +220,7 @@ def childfree_tree_factory(self): def _childfree_tree_factory(): return DataTree( - data=xr.Dataset({"z": ("y", [randint(1, 100) for _ in range(3)])}) + dataset=xr.Dataset({"z": ("y", [randint(1, 100) for _ in range(3)])}) ) return _childfree_tree_factory