Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.

Conversation

@keewis
Copy link
Member

@keewis keewis commented Feb 28, 2023

Copy link
Member

@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
Member

@TomNicholas TomNicholas Mar 7, 2023

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
Member 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)

@keewis
Copy link
Member Author

keewis commented Oct 8, 2024

looks like this has been fixed while migrating into xarray

@keewis keewis closed this Oct 8, 2024
@keewis keewis deleted the from_dict-root branch October 8, 2024 16:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants