MCPcopy Index your code
hub / github.com/pydata/xarray / _set_parent

Method _set_parent

xarray/core/treenode.py:96–111  ·  view source on GitHub ↗
(
        self, new_parent: Self | None, child_name: str | None = None
    )

Source from the content-addressed store, hash-verified

94 )
95
96 def _set_parent(
97 self, new_parent: Self | None, child_name: str | None = None
98 ) -> None:
99 # TODO is it possible to refactor in a way that removes this private method?
100
101 if new_parent is not None and not isinstance(new_parent, TreeNode):
102 raise TypeError(
103 "Parent nodes must be of type DataTree or None, "
104 f"not type {type(new_parent)}"
105 )
106
107 old_parent = self._parent
108 if new_parent is not old_parent:
109 self._check_loop(new_parent)
110 self._detach(old_parent)
111 self._attach(new_parent, child_name)
112
113 def _check_loop(self, new_parent: Self | None) -> None:
114 """Checks that assignment of this new parent will not create a cycle."""

Callers 7

orphanMethod · 0.95
test_parentingMethod · 0.95
test_parent_swapMethod · 0.95
childrenMethod · 0.80
_setMethod · 0.80

Calls 4

_check_loopMethod · 0.95
_detachMethod · 0.95
_attachMethod · 0.95
typeFunction · 0.85

Tested by 4

test_parentingMethod · 0.76
test_parent_swapMethod · 0.76