Skip to content

Commit

Permalink
fix by shallow copying
Browse files Browse the repository at this point in the history
  • Loading branch information
TomNicholas committed Jul 31, 2024
1 parent 4b7e367 commit 6c56b12
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions xarray/core/datatree.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,10 @@ def __init__(

super().__init__(name=name)
self._set_node_data(_coerce_to_dataset(data))
self.parent = parent
self.children = children

# shallow copy to avoid modifying arguments in-place (see GH issue #9196)
self.parent = parent.copy() if parent is not None else None
self.children = {name: child.copy() for name, child in children.items()}

def _set_node_data(self, ds: Dataset):
data_vars, coord_vars = _collect_data_and_coord_variables(ds)
Expand Down Expand Up @@ -770,7 +772,7 @@ def _replace_node(
if data is not _default:
self._set_node_data(ds)

self._children = children
self.children = children

def copy(
self: DataTree,
Expand Down

0 comments on commit 6c56b12

Please sign in to comment.