Skip to content

Commit 896b327

Browse files
committed
Add a note about counting leaves in a tree.
1 parent 47ef0d5 commit 896b327

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

docs/python-api.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,14 @@ Descendant nodes
507507
Tree.num_samples
508508
Tree.num_tracked_samples
509509
510+
Note that :meth:Tree.num_samples provides an efficient way to count samples under a node.
511+
However, samples and leaves are not always equivalent: some samples may be internal nodes,
512+
some leaves may not be samples (in unsimplified tree sequences), and the same node can be
513+
a leaf in one tree but internal in another. While `tree.num_samples` often equals the leaf
514+
count (particularly in simplified tree sequences without internal samples), a strict leaf
515+
count requires tree traversal, e.g. via `num_leaves = len(list(tree.leaves()))`.
516+
517+
510518
Multiple nodes
511519
.. autosummary::
512520
Tree.is_descendant

0 commit comments

Comments
 (0)