-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assigning to DataTree.coords should support full paths #9485
Comments
Oh dear. The problem is that In [11]: dt = DataTree(Dataset(coords={'x': 0}), children={'child': DataTree()})
In [12]: dt.update({'child/y': Variable(data=2, dims=())})
In [13]: dt
Out[13]:
<xarray.DataTree>
Group: /
│ Dimensions: ()
│ Coordinates:
│ x int64 8B 0
│ Data variables:
│ child/y int64 8B 2
└── Group: /child
In [15]: dt['child/y'] = Variable(data=2, dims=())
In [16]: dt
Out[16]:
<xarray.DataTree>
Group: /
│ Dimensions: ()
│ Coordinates:
│ x int64 8B 0
└── Group: /child
Dimensions: ()
Data variables:
y int64 8B 2 I think some refactoring to direct all these through the same codepath would help. Perhaps the general pattern should be more like: class DataTree:
def update(self, other: Mapping[str, Any]):
for k, v in other.items():
path = NodePath(k)
node_to_update = self._walk_to(path)
node_to_update._local_update({k: v}) |
Note that merging #9378 would have prevented the variable being assigned, instead raising a |
What is your issue?
When assigning to a full path with
DataTree.coords
, I expected to assign a coordinate to a child, not the root.Here's the behavior on
main
:Instead, I expected the result of assigning directly to the child node (without the duiplicate inherited coordinate, of course):
The text was updated successfully, but these errors were encountered: