Skip to content

Commit 2297752

Browse files
committed
Fix test_ld on numpy 2
1 parent 84dc4a3 commit 2297752

File tree

1 file changed

+10
-48
lines changed

1 file changed

+10
-48
lines changed

sgkit/tests/test_ld.py

Lines changed: 10 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
from typing import Optional
22

3-
import allel
4-
import dask.array as da
53
import numpy as np
64
import numpy.testing as npt
75
import pytest
86
from dask.dataframe import DataFrame
9-
from hypothesis import Phase, example, given, settings
107
from hypothesis import strategies as st
118
from hypothesis.extra.numpy import arrays
129

@@ -27,40 +24,27 @@ def test_rogers_huff_r_between():
2724
gnb = np.array([[0, 1, 2]])
2825
npt.assert_allclose(rogers_huff_r_between(gna[0], gnb[0]), 1.0, rtol=1e-06)
2926
npt.assert_allclose(rogers_huff_r2_between(gna[0], gnb[0]), 1.0, rtol=1e-06)
30-
npt.assert_allclose(
31-
allel.rogers_huff_r_between(gna, gnb),
32-
rogers_huff_r_between(gna[0], gnb[0]),
33-
rtol=1e-06,
34-
)
3527

3628
gna = np.array([[0, 1, 2]])
3729
gnb = np.array([[2, 1, 0]])
3830
npt.assert_allclose(rogers_huff_r_between(gna[0], gnb[0]), -1.0, rtol=1e-06)
3931
npt.assert_allclose(rogers_huff_r2_between(gna[0], gnb[0]), 1.0, rtol=1e-06)
40-
npt.assert_allclose(
41-
allel.rogers_huff_r_between(gna, gnb),
42-
rogers_huff_r_between(gna[0], gnb[0]),
43-
rtol=1e-06,
44-
)
4532

4633
gna = np.array([[0, 0, 0]])
4734
gnb = np.array([[1, 1, 1]])
4835
assert np.isnan(rogers_huff_r_between(gna[0], gnb[0]))
4936
assert np.isnan(rogers_huff_r2_between(gna[0], gnb[0]))
50-
assert np.isnan(allel.rogers_huff_r_between(gna, gnb))
5137

5238
gna = np.array([[1, 1, 1]])
5339
gnb = np.array([[1, 1, 1]])
5440
assert np.isnan(rogers_huff_r_between(gna[0], gnb[0]))
5541
assert np.isnan(rogers_huff_r2_between(gna[0], gnb[0]))
56-
assert np.isnan(allel.rogers_huff_r_between(gna, gnb))
5742

5843
# a case which fails if fastmath=True is enabled for rogers_huff_r_between
5944
gna = np.full((1, 49), 2)
6045
gnb = np.full((1, 49), 2)
6146
assert np.isnan(rogers_huff_r_between(gna[0], gnb[0]))
6247
assert np.isnan(rogers_huff_r2_between(gna[0], gnb[0]))
63-
assert np.isnan(allel.rogers_huff_r_between(gna, gnb))
6448

6549

6650
def ldm_df(
@@ -115,7 +99,16 @@ def test_threshold():
11599

116100
@pytest.mark.parametrize(
117101
"dtype",
118-
[dtype for k, v in np.sctypes.items() for dtype in v if k in ["int", "uint"]], # type: ignore
102+
[
103+
np.int8,
104+
np.int16,
105+
np.int32,
106+
np.int64,
107+
np.uint8,
108+
np.uint16,
109+
np.uint32,
110+
np.uint64,
111+
],
119112
)
120113
def test_dtypes(dtype):
121114
# Input matrices should work regardless of integer type
@@ -148,37 +141,6 @@ def ld_prune_args(draw):
148141
return x, window, step, threshold, chunks
149142

150143

151-
# Phases setting without shrinking for complex, conditional draws in
152-
# which shrinking wastes time and adds little information
153-
# (see https://hypothesis.readthedocs.io/en/latest/settings.html#hypothesis.settings.phases)
154-
PHASES_NO_SHRINK = (Phase.explicit, Phase.reuse, Phase.generate, Phase.target)
155-
156-
157-
@given(args=ld_prune_args()) # pylint: disable=no-value-for-parameter
158-
@settings(max_examples=50, deadline=None, phases=PHASES_NO_SHRINK)
159-
@example(args=(np.array([[1, 1], [1, 1]], dtype="uint8"), 1, 1, 0.0, -1))
160-
@pytest.mark.skip(
161-
reason="Hypothesis generates failures that need investigation: https://github.com/sgkit-dev/sgkit/issues/864"
162-
)
163-
def test_vs_skallel(args):
164-
x, size, step, threshold, chunks = args
165-
166-
ds = simulate_genotype_call_dataset(n_variant=x.shape[0], n_sample=x.shape[1])
167-
ds["call_dosage"] = (["variants", "samples"], da.asarray(x).rechunk({0: chunks}))
168-
ds = window_by_variant(ds, size=size, step=step)
169-
170-
ldm = ld_matrix(ds, threshold=threshold)
171-
has_duplicates = ldm.compute().duplicated(subset=["i", "j"]).any()
172-
assert not has_duplicates
173-
idx_drop_ds = maximal_independent_set(ldm)
174-
175-
idx_drop = np.sort(idx_drop_ds.ld_prune_index_to_drop.data)
176-
m = allel.locate_unlinked(x, size=size, step=step, threshold=threshold)
177-
idx_drop_ska = np.sort(np.argwhere(~m).squeeze(axis=1))
178-
179-
npt.assert_equal(idx_drop_ska, idx_drop)
180-
181-
182144
def test_scores():
183145
# Create zero row vectors except for 1st and 11th
184146
# (make them have non-zero variance)

0 commit comments

Comments
 (0)