Skip to content

Commit

Permalink
Make the first argument in DataTree.from_dict positional only (#9446)
Browse files Browse the repository at this point in the history
The fact that it has the non-descriptive name "d" is a good indication
that users should not be supplying it as a keyword argument.

(Alternatively, we could make a more descriptive name, but I think
positional only is also fine for now.)
  • Loading branch information
shoyer authored Sep 8, 2024
1 parent f97f999 commit 9a19d11
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions xarray/core/datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ def drop_nodes(
def from_dict(
cls,
d: Mapping[str, Dataset | DataTree | None],
/,
name: str | None = None,
) -> DataTree:
"""
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ def test_match(self):

def test_filter(self):
simpsons = DataTree.from_dict(
d={
{
"/": xr.Dataset({"age": 83}),
"/Herbert": xr.Dataset({"age": 40}),
"/Homer": xr.Dataset({"age": 39}),
Expand All @@ -1083,7 +1083,7 @@ def test_filter(self):
name="Abe",
)
expected = DataTree.from_dict(
d={
{
"/": xr.Dataset({"age": 83}),
"/Herbert": xr.Dataset({"age": 40}),
"/Homer": xr.Dataset({"age": 39}),
Expand Down
6 changes: 3 additions & 3 deletions xarray/tests/test_datatree_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def test_not_a_tree(self):
check_isomorphic("s", 1) # type: ignore[arg-type]

def test_different_widths(self):
dt1 = DataTree.from_dict(d={"a": empty})
dt2 = DataTree.from_dict(d={"b": empty, "c": empty})
dt1 = DataTree.from_dict({"a": empty})
dt2 = DataTree.from_dict({"b": empty, "c": empty})
expected_err_str = (
"Number of children on node '/' of the left object: 1\n"
"Number of children on node '/' of the right object: 2"
Expand Down Expand Up @@ -320,7 +320,7 @@ def weighted_mean(ds):

def test_alter_inplace_forbidden(self):
simpsons = DataTree.from_dict(
d={
{
"/": xr.Dataset({"age": 83}),
"/Herbert": xr.Dataset({"age": 40}),
"/Homer": xr.Dataset({"age": 39}),
Expand Down

0 comments on commit 9a19d11

Please sign in to comment.