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

Method find_common_ancestor

xarray/core/treenode.py:763–779  ·  view source on GitHub ↗

Find the first common ancestor of two nodes in the same tree. Raise ValueError if they are not in the same tree.

(self, other: Self)

Source from the content-addressed store, hash-verified

761 )
762
763 def find_common_ancestor(self, other: Self) -> Self:
764 """
765 Find the first common ancestor of two nodes in the same tree.
766
767 Raise ValueError if they are not in the same tree.
768 """
769 if self is other:
770 return self
771
772 other_paths = [op.path for op in other.parents]
773 for parent in (self, *self.parents):
774 if parent.path in other_paths:
775 return parent
776
777 raise NotFoundInTreeError(
778 "Cannot find common ancestor because nodes do not lie within the same tree"
779 )
780
781 def _path_to_ancestor(self, ancestor: Self) -> NodePath:
782 """Return the relative path from this node to the given ancestor node"""

Callers 1

relative_toMethod · 0.95

Calls 1

NotFoundInTreeErrorClass · 0.85

Tested by

no test coverage detected