Assigning to DataTree.coords should support full paths
Open
Nobody has claimed this yet.
bug
topic-DataTree
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
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:
In [36]: tree = DataTree(Dataset(coords={'x': 0}), children={'child': DataTree()})
In [37]: tree.coords['/child/y'] = 2
In [38]: tree
Out[38]:
<xarray.DataTree>
Group: /
│ Dimensions: ()
│ Coordinates:
│ x int64 8B 0
│ /child/y int64 8B 2
└── Group: /child
Instead, I expected the result of assigning directly to the child node (without the duiplicate inherited coordinate, of course):
In [40]: tree['/child'].coords['y'] = 2
In [41]: tree
Out[41]:
<xarray.DataTree>
Group: /
│ Dimensions: ()
│ Coordinates:
│ x int64 8B 0
└── Group: /child
Dimensions: ()
Coordinates:
x int64 8B 0
y int64 8B 2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the DataTree.coords assignment shown in the issue, comparing tree.coords['/child/y'] with tree['/child'].coords['y']. Trace how full-path coordinate assignments are resolved. Done means a full path assigns the coordinate to the child node without creating the duplicate inherited coordinate at the root.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100