We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4b7e367 commit 6c56b12Copy full SHA for 6c56b12
xarray/core/datatree.py
@@ -463,8 +463,10 @@ def __init__(
463
464
super().__init__(name=name)
465
self._set_node_data(_coerce_to_dataset(data))
466
- self.parent = parent
467
- self.children = children
+
+ # shallow copy to avoid modifying arguments in-place (see GH issue #9196)
468
+ self.parent = parent.copy() if parent is not None else None
469
+ self.children = {name: child.copy() for name, child in children.items()}
470
471
def _set_node_data(self, ds: Dataset):
472
data_vars, coord_vars = _collect_data_and_coord_variables(ds)
@@ -770,7 +772,7 @@ def _replace_node(
770
772
if data is not _default:
771
773
self._set_node_data(ds)
774
- self._children = children
775
+ self.children = children
776
777
def copy(
778
self: DataTree,
0 commit comments