Returns the object lying at the given path. Raises a KeyError if there is no object at the given path.
(self, path: str | NodePath)
| 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 | """ |