MCPcopy
hub / github.com/pydata/xarray / _set

Method _set

xarray/core/datatree.py:1016–1032  ·  view source on GitHub ↗

Set the child node or variable with the specified key to value. Counterpart to the public .get method, and also only works on the immediate node, not other nodes in the tree.

(self, key: str, val: DataTree | CoercibleValue)

Source from the content-addressed store, hash-verified

1014 raise ValueError(f"Invalid format for key: {key}")
1015
1016 def _set(self, key: str, val: DataTree | CoercibleValue) -> None:
1017 """
1018 Set the child node or variable with the specified key to value.
1019
1020 Counterpart to the public .get method, and also only works on the immediate node, not other nodes in the tree.
1021 """
1022 if isinstance(val, DataTree):
1023 # create and assign a shallow copy here so as not to alter original name of node in grafted tree
1024 new_node = val.copy(deep=False)
1025 new_node.name = key
1026 new_node._set_parent(new_parent=self, child_name=key)
1027 else:
1028 if not isinstance(val, DataArray | Variable):
1029 # accommodate other types that can be coerced into Variables
1030 val = DataArray(val)
1031
1032 self.update({key: val})
1033
1034 def __setitem__(
1035 self,

Callers

nothing calls this directly

Calls 4

copyMethod · 0.95
updateMethod · 0.95
DataArrayClass · 0.90
_set_parentMethod · 0.80

Tested by

no test coverage detected