Skip to content

Commit 8719775

Browse files
committed
small issue with Tajimas D tests
1 parent e32062e commit 8719775

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

python/tests/test_tree_stats.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,12 @@ def test_short_sequence_length(self):
668668

669669
@pytest.mark.slow
670670
def test_wright_fisher_slow(self, wf_fixture_slow):
671-
self.verify(wf_fixture_slow)
671+
_, ts = wf_fixture_slow
672+
self.verify(ts)
672673

673674
def test_wright_fisher(self, wf_fixture):
674-
self.verify(wf_fixture)
675+
_, ts = wf_fixture
676+
self.verify(ts)
675677

676678
def test_empty_ts(self):
677679
tables = tskit.TableCollection(1.0)
@@ -827,13 +829,13 @@ def wf_fixture_sims():
827829
)
828830
def wf_fixture(wf_fixture_sims, request):
829831
"""
830-
A collection of small Wright-Fisher simulations.
832+
A collection of small Wright-Fisher simulations. The name is returned for
833+
debugging purposes.
831834
"""
832-
ts = msprime.sim_mutations(
833-
wf_fixture_sims[request.param], rate=0.05, random_seed=1234
834-
)
835+
name = request.param
836+
ts = msprime.sim_mutations(wf_fixture_sims[name], rate=0.05, random_seed=1234)
835837
assert ts.num_mutations > 0
836-
return ts
838+
return name, ts
837839

838840

839841
@pytest.fixture(params=["unsimplified", "initial_generation"], scope="session")
@@ -842,11 +844,10 @@ def wf_fixture_slow(wf_fixture_sims, request):
842844
A few more small Wright-Fisher simulations. Despite the name, in total
843845
they take about the same time for tests together as wf_fixture.
844846
"""
845-
ts = msprime.sim_mutations(
846-
wf_fixture_sims[request.param], rate=0.05, random_seed=1234
847-
)
847+
name = request.param
848+
ts = msprime.sim_mutations(wf_fixture_sims[name], rate=0.05, random_seed=1234)
848849
assert ts.num_mutations > 0
849-
return ts
850+
return name, ts
850851

851852

852853
@pytest.fixture(scope="session")
@@ -1107,12 +1108,12 @@ def test_many_trees_sequence_length_infinite_sites(
11071108
self.verify(ts)
11081109

11091110
def test_wright_fisher(self, wf_fixture):
1110-
ts = wf_fixture
1111+
_, ts = wf_fixture
11111112
assert ts.num_sites > 0
11121113
self.verify(ts)
11131114

11141115
def test_wright_fisher_slow(self, wf_fixture_slow):
1115-
ts = wf_fixture_slow
1116+
_, ts = wf_fixture_slow
11161117
assert ts.num_sites > 0
11171118
self.verify(ts)
11181119

@@ -1130,7 +1131,7 @@ def example_sample_sets(ts, min_size=1):
11301131
number of sample sets returned in each example must be at least min_size
11311132
"""
11321133
samples = ts.samples()
1133-
np.random.shuffle(samples)
1134+
np.random.shuffle(samples) # <-- no seed
11341135
splits = np.array_split(samples, min_size)
11351136
yield splits
11361137
yield [[s] for s in samples]
@@ -1748,6 +1749,12 @@ def verify_persite_tajimas_d(self, ts, sample_sets):
17481749
sigma1 = ts.Tajimas_D(sample_sets, windows=windows, mode=self.mode)
17491750
sigma2 = site_tajimas_d(ts, sample_sets, windows=windows)
17501751
assert sigma1.shape == sigma2.shape
1752+
# floating point error can lead in strange cases to
1753+
# +/-inf in our implementation here and nan in the ts version
1754+
f1 = np.isfinite(sigma1)
1755+
f2 = np.isfinite(sigma2)
1756+
assert np.all(f1 == f2)
1757+
sigma2[~f2] = np.nan
17511758
self.assertArrayAlmostEqual(sigma1, sigma2)
17521759

17531760

0 commit comments

Comments
 (0)