Skip to content

Commit 1d2d878

Browse files
committed
Test moving_statistic preserves dtype
1 parent 7f99d15 commit 1d2d878

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sgkit/tests/test_window.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@
99
@pytest.mark.parametrize(
1010
"length, chunks, size, step", [(12, 6, 4, 4), (12, 6, 4, 2), (12, 5, 4, 4)]
1111
)
12-
def test_moving_statistic_1d(length, chunks, size, step):
13-
values = da.from_array(np.arange(length), chunks=chunks)
12+
@pytest.mark.parametrize("dtype", [np.int64, np.float32, np.float64])
13+
def test_moving_statistic_1d(length, chunks, size, step, dtype):
14+
values = da.from_array(np.arange(length, dtype=dtype), chunks=chunks)
1415

1516
stat = moving_statistic(values, np.sum, size=size, step=step, dtype=values.dtype)
1617
stat = stat.compute()
1718
if length % size != 0 or size != step:
1819
# scikit-allel misses final window in this case
1920
stat = stat[:-1]
21+
assert stat.dtype == dtype
2022

2123
values_sa = np.arange(length)
2224
stat_sa = allel.moving_statistic(values_sa, np.sum, size=size, step=step)
@@ -27,8 +29,9 @@ def test_moving_statistic_1d(length, chunks, size, step):
2729
@pytest.mark.parametrize(
2830
"length, chunks, size, step", [(12, 6, 4, 4), (12, 6, 4, 2), (12, 5, 4, 4)]
2931
)
30-
def test_moving_statistic_2d(length, chunks, size, step):
31-
arr = np.arange(length * 3).reshape(length, 3)
32+
@pytest.mark.parametrize("dtype", [np.int64, np.float32, np.float64])
33+
def test_moving_statistic_2d(length, chunks, size, step, dtype):
34+
arr = np.arange(length * 3, dtype=dtype).reshape(length, 3)
3235

3336
def sum_cols(x):
3437
return np.sum(x, axis=0)
@@ -39,6 +42,7 @@ def sum_cols(x):
3942
if length % size != 0 or size != step:
4043
# scikit-allel misses final window in this case
4144
stat = stat[:-1]
45+
assert stat.dtype == dtype
4246

4347
values_sa = arr
4448
stat_sa = allel.moving_statistic(values_sa, sum_cols, size=size, step=step)

0 commit comments

Comments
 (0)