Skip to content
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

allow DataTree objects as root node in from_dict #221

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

keewis
Copy link
Contributor

@keewis keewis commented Feb 28, 2023

Copy link
Collaborator

@TomNicholas TomNicholas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @keewis ! I have one comment about possible unintended behavior here.

if not isinstance(root_data, cls):
obj = cls(name=name, data=root_data, parent=None, children=None)
else:
obj = root_data.copy()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is potential for bugs here - .copy() will copy child nodes too, so if root_data has children already they will presumably be copied into the new tree. You could also then double-specify the contents of a single node, once as the child of the root and again in the supplied dict.

In fact your previous PR might do this too - I think we should decide what we want the behavior to be: either drop all children of supplied nodes or explicitly test that we keep children too.

If we do want to drop the children it would probably be clearer to just create a new node using a copy of the supplied node's name and data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit similar to what xarray does already when passing DataArray objects with coordinates to the Dataset constructor / Dataset.assign*: those coordinates will be carried over (unintentionally overriding coordinates explicitly passed in the same call).

I'm not sure if we need to copy the behavior, though.

I didn't have a need for it ever since opening this PR, so this is also pretty low-priority for me (as you might have guessed from the long delay)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants