Skip to content

Commit

Permalink
Deprecate Tree.num_nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
hyanwong committed Nov 29, 2021
1 parent 1e15ea0 commit 2025dbf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions python/CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

**Breaking changes**

- The ``Tree.num_nodes`` method is now deprecated with a warning, because it confusingly
returns the number of nodes in the entire tree sequence, rather than in the tree.
(:user:`hyanwong`, :issue:`1966` :pr:`1968`)

- The CLI ``info`` command now gives more detailed information on the tree sequence
(:user:`benjeffery`, :pr:`1611`)

Expand Down
14 changes: 12 additions & 2 deletions python/tskit/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -1403,11 +1403,21 @@ def is_descendant(self, u, v):
def num_nodes(self):
"""
Returns the number of nodes in the :class:`TreeSequence` this tree is in.
Equivalent to ``tree.tree_sequence.num_nodes``. To find the number of
nodes that are reachable from all roots use ``len(list(tree.nodes()))``.
Equivalent to ``tree.tree_sequence.num_nodes``.
.. deprecated:: 0.4
Use :func:`Tree.tree_sequence.num_nodes` if you want the number of nodes
in the entire tree sequence, or ``len(list(tree.nodes()))`` to find the
number of nodes that are reachable from all roots in this tree.
:rtype: int
"""
warnings.warn(
"This property is a deprecated alias for Tree.tree_sequence.num_nodes"
"and will be removed in the future",
RuntimeWarning,
)
return self._ll_tree.get_num_nodes()

@property
Expand Down

0 comments on commit 2025dbf

Please sign in to comment.