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

Added a move_to () metho changed #238

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions datatree/datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,3 +1412,9 @@ def to_zarr(

def plot(self):
raise NotImplementedError

def move_to(self, new_parent: Tree | None) -> DataTree:
self.parent = new_parent
# We take advantage of the parent setter implemented above.
# the parent setter also calls the _set_parent() method, thus no need to repeat it here.
return self
2 changes: 2 additions & 0 deletions datatree/treenode.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def _detach(self, parent: Tree | None) -> None:
if child is not self
}
)
# Deleting this detached node from the children dictionary of the old parent
parent._children[self.name] = None
self._parent = None
self._post_detach(parent)

Expand Down