Skip to content

Datatree: parent of new nodes is not assigned properly in update #9345

@flamingbear

Description

@flamingbear

What is your issue?

Originally posted by @keewis in xarray-contrib/datatree#203

there's something weird happening when assigning nodes using update:

In [1]: import datatree
   ...: import xarray as xr
   ...: 
   ...: tree1 = datatree.DataTree.from_dict({"/a/b": xr.Dataset()})
   ...: node = datatree.DataTree()
   ...: 
   ...: tree2 = tree1.copy()
   ...: tree2.update({"c": node})
   ...: 
   ...: for node in tree3.subtree:
   ...:     print(node.path, node.name, id(node.root))
/ None 140512169735136
/a a 140512169735136
/a/b b 140512169735136
/ c 140512169735248

(the parent of node is None, so its root is the node itself)

So it seems with update / assign you can end up with a inconsistent tree? With xarray-contrib/datatree#201, that inconsistent tree fails to copy because relative_to raises an error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-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