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

Method _path_to_ancestor

xarray/core/treenode.py:781–796  ·  view source on GitHub ↗

Return the relative path from this node to the given ancestor node

(self, ancestor: Self)

Source from the content-addressed store, hash-verified

779 )
780
781 def _path_to_ancestor(self, ancestor: Self) -> NodePath:
782 """Return the relative path from this node to the given ancestor node"""
783
784 if not self.same_tree(ancestor):
785 raise NotFoundInTreeError(
786 "Cannot find relative path to ancestor because nodes do not lie within the same tree"
787 )
788 if ancestor.path not in [a.path for a in (self, *self.parents)]:
789 raise NotFoundInTreeError(
790 "Cannot find relative path to ancestor because given node is not an ancestor of this node"
791 )
792
793 parents_paths = [parent.path for parent in (self, *self.parents)]
794 generation_gap = list(parents_paths).index(ancestor.path)
795 path_upwards = "../" * generation_gap if generation_gap > 0 else "."
796 return NodePath(path_upwards)
797
798
799class TreeIsomorphismError(ValueError):

Callers 1

relative_toMethod · 0.80

Calls 4

NotFoundInTreeErrorClass · 0.85
NodePathClass · 0.85
same_treeMethod · 0.80
indexMethod · 0.45

Tested by

no test coverage detected