Skip to content

Commit 77b9259

Browse files
committed
Change .length to .span
1 parent 6e411ff commit 77b9259

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

python/tests/test_highlevel.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,11 +2012,11 @@ def test_apis(self):
20122012
self.assertEqual(t1.get_root(), t1.root)
20132013
self.assertEqual(t1.get_index(), t1.index)
20142014
self.assertEqual(t1.get_interval(), t1.interval)
2015-
self.assertEqual(t1.get_length(), t1.length)
20162015
self.assertEqual(t1.get_sample_size(), t1.sample_size)
20172016
self.assertEqual(t1.get_num_mutations(), t1.num_mutations)
20182017
self.assertEqual(t1.get_parent_dict(), t1.parent_dict)
20192018
self.assertEqual(t1.get_total_branch_length(), t1.total_branch_length)
2019+
self.assertEqual(t1.span, t1.interval[1] - t1.interval[0])
20202020
# node properties
20212021
root = t1.get_root()
20222022
for node in t1.nodes():
@@ -2036,6 +2036,11 @@ def test_apis(self):
20362036
self.assertEqual(t1.get_mrca(*pair), t1.mrca(*pair))
20372037
self.assertEqual(t1.get_tmrca(*pair), t1.tmrca(*pair))
20382038

2039+
def test_deprecated_apis(self):
2040+
t1 = self.get_tree()
2041+
self.assertEqual(t1.get_length(), t1.span)
2042+
self.assertEqual(t1.length, t1.span)
2043+
20392044
def test_seek_index(self):
20402045
ts = msprime.simulate(10, recombination_rate=3, length=5, random_seed=42)
20412046
N = ts.num_trees

python/tskit/trees.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -604,9 +604,8 @@ def branch_length(self, u):
604604
605605
>>> tree.time(tree.parent(u)) - tree.time(u)
606606
607-
Note that this is not related to the value returned by
608-
:attr:`.length`, which describes the length of the interval
609-
covered by the tree in genomic coordinates.
607+
(note that this is not related to the property :attr:`.length` which
608+
is a deprecated alias for the genomic :attr:`.span` covered by a tree)
610609
611610
:param int u: The node of interest.
612611
:return: The branch length from u to its parent.
@@ -915,17 +914,22 @@ def interval(self):
915914
return self._ll_tree.get_left(), self._ll_tree.get_right()
916915

917916
def get_length(self):
918-
# Deprecated alias for self.length
917+
# Deprecated alias for self.span
919918
return self.length
920919

921920
@property
922921
def length(self):
922+
# Deprecated alias for self.span
923+
return self.span
924+
925+
@property
926+
def span(self):
923927
"""
924-
Returns the length of the genomic interval that this tree represents.
928+
Returns the genomic distance that this tree spans.
925929
This is defined as :math:`r - l`, where :math:`(l, r)` is the genomic
926930
interval returned by :attr:`.interval`.
927931
928-
:return: The length of the genomic interval covered by this tree.
932+
:return: The genomic distance covered by this tree.
929933
:rtype: int
930934
"""
931935
left, right = self.get_interval()
@@ -2631,9 +2635,9 @@ def mean_descendants(self, reference_sets):
26312635
Computes for every node the mean number of samples in each of the
26322636
`reference_sets` that descend from that node, averaged over the
26332637
portions of the genome for which the node is ancestral to *any* sample.
2634-
The output is an array, `C[node, j]`, which reports the total length of
2638+
The output is an array, `C[node, j]`, which reports the total span of
26352639
all genomes in `reference_sets[j]` that inherit from `node`, divided by
2636-
the total length of the genome on which `node` is an ancestor to any
2640+
the total span of the genome on which `node` is an ancestor to any
26372641
sample in the tree sequence.
26382642
26392643
.. note:: This interface *may change*, particularly the normalization by
@@ -2689,7 +2693,7 @@ def genealogical_nearest_neighbours(self, focal, reference_sets, num_threads=0):
26892693
# TODO this may not be a good name because there is another version of the
26902694
# statistic which may be occasionally useful where we return the tree-by-tree
26912695
# value. We could do this by adding an extra dimension to the returned array
2692-
# which would give the values tree-by-tree. The tree lengths can be computed
2696+
# which would give the values tree-by-tree. The tree spans can be computed
26932697
# easily enough, *but* there may be occasions when the statistic isn't
26942698
# defined over particular trees.
26952699
#

0 commit comments

Comments
 (0)