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

Method __setitem__

xarray/core/datatree.py:1034–1058  ·  view source on GitHub ↗

Add either a child node or an array to the tree, at any position. Data can be added anywhere, and new nodes will be created to cross the path to the new location if necessary. If there is already a node at the given location, then if value is a Node class or Dataset it wil

(
        self,
        key: str,
        value: Any,
    )

Source from the content-addressed store, hash-verified

1032 self.update({key: val})
1033
1034 def __setitem__(
1035 self,
1036 key: str,
1037 value: Any,
1038 ) -> None:
1039 """
1040 Add either a child node or an array to the tree, at any position.
1041
1042 Data can be added anywhere, and new nodes will be created to cross the path to the new location if necessary.
1043
1044 If there is already a node at the given location, then if value is a Node class or Dataset it will overwrite the
1045 data already present at that node, and if value is a single array, it will be merged with it.
1046 """
1047 # TODO xarray.Dataset accepts other possibilities, how do we exactly replicate all the behaviour?
1048 if utils.is_dict_like(key):
1049 raise NotImplementedError
1050 elif isinstance(key, str):
1051 # TODO should possibly deal with hashables in general?
1052 # path-like: a name of a node/variable, or path to a node/variable
1053 path = NodePath(key)
1054 if isinstance(value, Dataset):
1055 value = DataTree(dataset=value)
1056 return self._set_item(path, value, new_nodes_along_path=True)
1057 else:
1058 raise ValueError("Invalid format for key")
1059
1060 def __delitem__(self, key: str) -> None:
1061 """Remove a variable or child node from this datatree node."""

Callers

nothing calls this directly

Calls 3

NodePathClass · 0.90
DataTreeClass · 0.85
_set_itemMethod · 0.80

Tested by

no test coverage detected