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

Method drop_nodes

xarray/core/datatree.py:1172–1208  ·  view source on GitHub ↗

Drop child nodes from this node. Parameters ---------- names : str or iterable of str Name(s) of nodes to drop. errors : {"raise", "ignore"}, default: "raise" If 'raise', raises a KeyError if any of the node names passed a

(
        self: DataTree, names: str | Iterable[str], *, errors: ErrorOptions = "raise"
    )

Source from the content-addressed store, hash-verified

1170 return dt
1171
1172 def drop_nodes(
1173 self: DataTree, names: str | Iterable[str], *, errors: ErrorOptions = "raise"
1174 ) -> DataTree:
1175 """
1176 Drop child nodes from this node.
1177
1178 Parameters
1179 ----------
1180 names : str or iterable of str
1181 Name(s) of nodes to drop.
1182 errors : {"raise", "ignore"}, default: "raise"
1183 If 'raise', raises a KeyError if any of the node names
1184 passed are not present as children of this node. If 'ignore',
1185 any given names that are present are dropped and no error is raised.
1186
1187 Returns
1188 -------
1189 dropped : DataTree
1190 A copy of the node with the specified children dropped.
1191 """
1192 # the Iterable check is required for mypy
1193 if isinstance(names, str) or not isinstance(names, Iterable):
1194 names = {names}
1195 else:
1196 names = set(names)
1197
1198 if errors == "raise":
1199 extra = names - set(self.children)
1200 if extra:
1201 raise KeyError(f"Cannot drop all nodes - nodes {extra} not present")
1202
1203 result = self.copy()
1204 children_to_keep = {
1205 name: child for name, child in result.children.items() if name not in names
1206 }
1207 result._replace_node(children=children_to_keep)
1208 return result
1209
1210 @overload
1211 @classmethod

Callers 1

test_drop_nodesMethod · 0.80

Calls 3

itemsMethod · 0.80
_replace_nodeMethod · 0.80
copyMethod · 0.45

Tested by 1

test_drop_nodesMethod · 0.64