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

Method assign

xarray/core/datatree.py:1130–1170  ·  view source on GitHub ↗

Assign new data variables or child nodes to a DataTree, returning a new object with all the original items in addition to the new ones. Parameters ---------- items : mapping of hashable to Any Mapping from variable or child node names to the new

(
        self, items: Mapping[Any, Any] | None = None, **items_kwargs: Any
    )

Source from the content-addressed store, hash-verified

1128 self._replace_node(data, children=merged_children)
1129
1130 def assign(
1131 self, items: Mapping[Any, Any] | None = None, **items_kwargs: Any
1132 ) -> DataTree:
1133 """
1134 Assign new data variables or child nodes to a DataTree, returning a new object
1135 with all the original items in addition to the new ones.
1136
1137 Parameters
1138 ----------
1139 items : mapping of hashable to Any
1140 Mapping from variable or child node names to the new values. If the new values
1141 are callable, they are computed on the Dataset and assigned to new
1142 data variables. If the values are not callable, (e.g. a DataTree, DataArray,
1143 scalar, or array), they are simply assigned.
1144 **items_kwargs
1145 The keyword arguments form of ``variables``.
1146 One of variables or variables_kwargs must be provided.
1147
1148 Returns
1149 -------
1150 dt : DataTree
1151 A new DataTree with the new variables or children in addition to all the
1152 existing items.
1153
1154 Notes
1155 -----
1156 Since ``kwargs`` is a dictionary, the order of your arguments may not
1157 be preserved, and so the order of the new variables is not well-defined.
1158 Assigning multiple items within the same ``assign`` is
1159 possible, but you cannot reference other variables created within the
1160 same ``assign`` call.
1161
1162 See Also
1163 --------
1164 xarray.Dataset.assign
1165 pandas.DataFrame.assign
1166 """
1167 items = either_dict_or_kwargs(items, items_kwargs, "assign")
1168 dt = self.copy()
1169 dt.update(items)
1170 return dt
1171
1172 def drop_nodes(
1173 self: DataTree, names: str | Iterable[str], *, errors: ErrorOptions = "raise"

Callers 1

test_assignMethod · 0.95

Calls 3

either_dict_or_kwargsFunction · 0.90
copyMethod · 0.45
updateMethod · 0.45

Tested by 1

test_assignMethod · 0.76