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

Method _check_children

xarray/core/treenode.py:197–218  ·  view source on GitHub ↗

Check children for correct types and for any duplicates.

(children: Mapping[str, TreeNode])

Source from the content-addressed store, hash-verified

195
196 @staticmethod
197 def _check_children(children: Mapping[str, TreeNode]) -> None:
198 """Check children for correct types and for any duplicates."""
199 if not is_dict_like(children):
200 raise TypeError(
201 "children must be a dict-like mapping from names to node objects"
202 )
203
204 seen = set()
205 for name, child in children.items():
206 if not isinstance(child, TreeNode):
207 raise TypeError(
208 f"Cannot add object {name}. It is of type {type(child)}, "
209 "but can only add children of type DataTree"
210 )
211
212 childid = id(child)
213 if childid not in seen:
214 seen.add(childid)
215 else:
216 raise InvalidTreeError(
217 f"Cannot add same node {name} multiple times as different children."
218 )
219
220 def __repr__(self) -> str:
221 return f"TreeNode(children={dict(self._children)})"

Callers 1

childrenMethod · 0.95

Calls 5

is_dict_likeFunction · 0.90
typeFunction · 0.85
InvalidTreeErrorClass · 0.85
itemsMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected