Skip to content
This repository was archived by the owner on Oct 24, 2024. It is now read-only.

Commit a1cdfb4

Browse files
committed
New PR
1 parent d3ea0db commit a1cdfb4

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

datatree/treenode.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,14 @@ def parents(self: Tree) -> Tuple[Tree, ...]:
273273
@property
274274
def ancestors(self: Tree) -> Tuple[Tree, ...]:
275275
"""All parent nodes and their parent nodes, starting with the most distant."""
276+
277+
from warnings import warn
278+
279+
warn(
280+
"`ancestors` has been deprecated, and in the future will raise an error."
281+
"Please use `parents`. Example: `tuple(reversed(node.parents))`",
282+
DeprecationWarning,
283+
)
276284
return tuple(reversed(self.parents))
277285

278286
@property
@@ -369,7 +377,7 @@ def level(self: Tree) -> int:
369377
depth
370378
width
371379
"""
372-
return len(self.ancestors)
380+
return len(self.parents)
373381

374382
@property
375383
def depth(self: Tree) -> int:
@@ -609,7 +617,7 @@ def path(self) -> str:
609617
if self.is_root:
610618
return "/"
611619
else:
612-
root, *ancestors = self.ancestors
620+
root, *ancestors = tuple(reversed(self.parents))
613621
# don't include name of root because (a) root might not have a name & (b) we want path relative to root.
614622
names = [*(node.name for node in ancestors), self.name]
615623
return "/" + "/".join(names)
@@ -660,7 +668,7 @@ def _path_to_ancestor(self, ancestor: NamedNode) -> NodePath:
660668
raise NotFoundInTreeError(
661669
"Cannot find relative path to ancestor because nodes do not lie within the same tree"
662670
)
663-
if ancestor.path not in list(a.path for a in (*self.ancestors, self)):
671+
if ancestor.path not in list(a.path for a in (self, *self.parents)):
664672
raise NotFoundInTreeError(
665673
"Cannot find relative path to ancestor because given node is not an ancestor of this node"
666674
)

0 commit comments

Comments
 (0)