Skip to content

Assigning to DataTree.coords should support full paths #9485

@shoyer

Description

@shoyer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugtopic-DataTreeRelated to the implementation of a DataTree class

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions