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

Method _get_item

xarray/core/treenode.py:534–563  ·  view source on GitHub ↗

Returns the object lying at the given path. Raises a KeyError if there is no object at the given path.

(self, path: str | NodePath)

Source from the content-addressed store, hash-verified

532 # TODO `._walk` method to be called by both `_get_item` and `_set_item`
533
534 def _get_item(self, path: str | NodePath) -> Self | DataArray:
535 """
536 Returns the object lying at the given path.
537
538 Raises a KeyError if there is no object at the given path.
539 """
540 if isinstance(path, str):
541 path = NodePath(path)
542
543 if path.root:
544 current_node = self.root
545 _root, *parts = list(path.parts)
546 else:
547 current_node = self
548 parts = list(path.parts)
549
550 for part in parts:
551 if part == "..":
552 if current_node.parent is None:
553 raise KeyError(f"Could not find node at {path}")
554 else:
555 current_node = current_node.parent
556 elif part in ("", "."):
557 pass
558 else:
559 child = current_node.get(part)
560 if child is None:
561 raise KeyError(f"Could not find node at {path}")
562 current_node = child
563 return current_node
564
565 def _set(self, key: str, val: Any) -> None:
566 """

Callers 4

test_get_childMethod · 0.95
__getitem__Method · 0.80
test_get_upwardsMethod · 0.80
test_get_from_rootMethod · 0.80

Calls 2

NodePathClass · 0.85
getMethod · 0.45

Tested by 3

test_get_childMethod · 0.76
test_get_upwardsMethod · 0.64
test_get_from_rootMethod · 0.64