Skip to content

Commit b8464ba

Browse files
committed
Keep Ne as deprecated alias for population_size
1 parent 377aae6 commit b8464ba

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

tests/test_inference.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import tsdate
3636
from tsdate.base import LIN
3737
from tsdate.base import LOG
38+
from tsdate.demography import PopulationSizeHistory
3839

3940

4041
class TestPrebuilt(unittest.TestCase):
@@ -59,6 +60,14 @@ def test_bad_population_size(self):
5960
with pytest.raises(ValueError, match="greater than 0"):
6061
tsdate.date(ts, mutation_rate=None, population_size=Ne)
6162

63+
def test_both_ne_and_population_size_specified(self):
64+
ts = utility_functions.two_tree_mutation_ts()
65+
with pytest.raises(ValueError, match="may be specified"):
66+
tsdate.date(
67+
ts, mutation_rate=None, population_size=PopulationSizeHistory(1), Ne=1
68+
)
69+
tsdate.date(ts, mutation_rate=None, Ne=PopulationSizeHistory(1))
70+
6271
def test_dangling_failure(self):
6372
ts = utility_functions.single_tree_ts_n2_dangling()
6473
with pytest.raises(ValueError, match="simplified"):

tsdate/core.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,7 @@ def date(
937937
time_units=None,
938938
priors=None,
939939
*,
940+
Ne=None,
940941
return_posteriors=None,
941942
progress=False,
942943
**kwargs,
@@ -966,12 +967,12 @@ def date(
966967
967968
:param TreeSequence tree_sequence: The input :class:`tskit.TreeSequence`, treated as
968969
one whose non-sample nodes are undated.
969-
:param float population_size: The estimated (diploid) effective population
970-
size used to construct the (default) conditional coalescent prior. This may
971-
be a single value, or a two-column array of epoch breakpoints and effective
972-
population sizes within epochs. These are used when ``priors`` is ``None``.
973-
Conversely, if ``priors`` is not ``None``, no ``population_size`` value
974-
should be given.
970+
:param PopulationSizeHistory population_size: The estimated (diploid) effective
971+
population size used to construct the (default) conditional coalescent
972+
prior. This may be a single value (for a population with constant size), or
973+
a :class:`PopulationSizeHistory` object (for a population with time-varying
974+
size). This is used when ``priors`` is ``None``. Conversely, if ``priors``
975+
is not ``None``, no ``population_size`` value should be given.
975976
:param float mutation_rate: The estimated mutation rate per unit of genome per
976977
unit time. If provided, the dating algorithm will use a mutation rate clock to
977978
help estimate node dates. Default: ``None``
@@ -1009,13 +1010,25 @@ def date(
10091010
Ignoring outside root provides greater stability when dating tree sequences
10101011
inferred from real data. Default: False
10111012
:param bool progress: Whether to display a progress bar. Default: False
1013+
:param float Ne: the estimated (diploid) effective population size used to
1014+
construct the (default) conditional coalescent prior. This is used when
1015+
``priors`` is ``None``. Conversely, if ``priors`` is not ``None``, no
1016+
``population_size`` value should be given. (Deprecated, use the
1017+
``population_size`` argument instead).
10121018
:return: A copy of the input tree sequence but with altered node times, or (if
10131019
``return_posteriors`` is True) a tuple of that tree sequence plus a dictionary
10141020
of posterior probabilities from the "inside_outside" estimation ``method``.
10151021
:rtype: tskit.TreeSequence or (tskit.TreeSequence, dict)
10161022
"""
10171023
if time_units is None:
10181024
time_units = "generations"
1025+
if Ne is not None:
1026+
if population_size is not None:
1027+
raise ValueError(
1028+
"Only one of Ne (deprecated) or population_size may be specified"
1029+
)
1030+
else:
1031+
population_size = Ne
10191032
tree_sequence, dates, posteriors, timepoints, eps, nds = get_dates(
10201033
tree_sequence,
10211034
population_size=population_size,

0 commit comments

Comments
 (0)