Skip to content

Commit 41dbc4b

Browse files
lithomas1lucascolley
authored andcommitted
fix ndimage and misc tests
1 parent 5a6d17a commit 41dbc4b

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

scipy/ndimage/tests/test_filters.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,9 @@ def test_rank06(self, xp):
18451845
@skip_xp_backends("jax.numpy",
18461846
reason="assignment destination is read-only",
18471847
)
1848+
@skip_xp_backends("dask.array",
1849+
reason="wrong answer",
1850+
)
18481851
def test_rank06_overlap(self, xp):
18491852
array = xp.asarray([[3, 2, 5, 1, 4],
18501853
[5, 8, 3, 7, 1],

scipy/ndimage/tests/test_measurements.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def test_label_output_dtype(xp):
366366
assert output.dtype == t
367367

368368

369-
@xfail_xp_backends('dask.array', reason='Dask does not raise')
369+
@skip_xp_backends('dask.array', reason='Dask does not raise')
370370
@xfail_xp_backends('jax.numpy', reason='JAX does not raise')
371371
def test_label_output_wrong_size(xp):
372372
data = xp.ones([5])
@@ -555,6 +555,7 @@ def test_value_indices02(xp):
555555
ndimage.value_indices(data)
556556

557557

558+
@skip_xp_backends("dask.array", reason="len on data-dependent output shapes")
558559
def test_value_indices03(xp):
559560
"Test different input array shapes, from 1-D to 4-D"
560561
for shape in [(36,), (18, 2), (3, 3, 4), (3, 3, 2, 2)]:
@@ -674,6 +675,7 @@ def test_sum11(xp):
674675
assert_almost_equal(output, xp.asarray(6.0), check_0d=False)
675676

676677

678+
@skip_xp_backends("dask.array", reason="data-dependent output shapes")
677679
def test_sum12(xp):
678680
labels = xp.asarray([[1, 2], [2, 4]], dtype=xp.int8)
679681
for type in types:
@@ -683,6 +685,7 @@ def test_sum12(xp):
683685
assert_array_almost_equal(output, xp.asarray([4.0, 0.0, 5.0]))
684686

685687

688+
@skip_xp_backends("dask.array", reason="data-dependent output shapes")
686689
def test_sum_labels(xp):
687690
labels = xp.asarray([[1, 2], [2, 4]], dtype=xp.int8)
688691
for type in types:
@@ -695,7 +698,7 @@ def test_sum_labels(xp):
695698
assert xp.all(output_sum == output_labels)
696699
assert_array_almost_equal(output_labels, xp.asarray([4.0, 0.0, 5.0]))
697700

698-
701+
@skip_xp_backends("dask.array", reason="dask outputs wrong results here")
699702
def test_mean01(xp):
700703
labels = np.asarray([1, 0], dtype=bool)
701704
labels = xp.asarray(labels)
@@ -706,6 +709,7 @@ def test_mean01(xp):
706709
assert_almost_equal(output, xp.asarray(2.0), check_0d=False)
707710

708711

712+
@skip_xp_backends("dask.array", reason="dask outputs wrong results here")
709713
def test_mean02(xp):
710714
labels = np.asarray([1, 0], dtype=bool)
711715
input = np.asarray([[1, 2], [3, 4]], dtype=bool)
@@ -716,6 +720,7 @@ def test_mean02(xp):
716720
assert_almost_equal(output, xp.asarray(1.0), check_0d=False)
717721

718722

723+
@skip_xp_backends("dask.array", reason="dask outputs wrong results here")
719724
def test_mean03(xp):
720725
labels = xp.asarray([1, 2])
721726
for type in types:
@@ -726,6 +731,7 @@ def test_mean03(xp):
726731
assert_almost_equal(output, xp.asarray(3.0), check_0d=False)
727732

728733

734+
@skip_xp_backends("dask.array", reason="dask outputs wrong results here")
729735
def test_mean04(xp):
730736
labels = xp.asarray([[1, 2], [2, 4]], dtype=xp.int8)
731737
with np.errstate(all='ignore'):
@@ -829,6 +835,7 @@ def test_maximum05(xp):
829835
assert ndimage.maximum(x) == -1
830836

831837

838+
@pytest.mark.filterwarnings("ignore::FutureWarning:dask")
832839
def test_median01(xp):
833840
a = xp.asarray([[1, 2, 0, 1],
834841
[5, 3, 0, 4],
@@ -851,6 +858,7 @@ def test_median02(xp):
851858
assert_almost_equal(output, xp.asarray(1.0), check_0d=False)
852859

853860

861+
@skip_xp_backends("dask.array", reason="dask.array.median only implemented for along an axis.")
854862
def test_median03(xp):
855863
a = xp.asarray([[1, 2, 0, 1],
856864
[5, 3, 0, 4],
@@ -864,14 +872,15 @@ def test_median03(xp):
864872
assert_almost_equal(output, xp.asarray(3.0), check_0d=False)
865873

866874

875+
@skip_xp_backends("dask.array", reason="Crash inside dask searchsorted")
867876
def test_median_gh12836_bool(xp):
868877
# test boolean addition fix on example from gh-12836
869878
a = np.asarray([1, 1], dtype=bool)
870879
a = xp.asarray(a)
871880
output = ndimage.median(a, labels=xp.ones((2,)), index=xp.asarray([1]))
872881
assert_array_almost_equal(output, xp.asarray([1.0]))
873882

874-
883+
@skip_xp_backends("dask.array", reason="Crash inside dask searchsorted")
875884
def test_median_no_int_overflow(xp):
876885
# test integer overflow fix on example from gh-12836
877886
a = xp.asarray([65, 70], dtype=xp.int8)
@@ -912,7 +921,9 @@ def test_variance04(xp):
912921
output = ndimage.variance(input)
913922
assert_almost_equal(output, xp.asarray(0.25), check_0d=False)
914923

915-
924+
# dask.array is maybe due to failed conversion to numpy?
925+
# array-api-strict should've caught use of non array API functions I think
926+
@skip_xp_backends("dask.array", reason="conjugate called on dask.array which doesn't exist")
916927
def test_variance05(xp):
917928
labels = xp.asarray([2, 2, 3])
918929
for type in types:
@@ -922,7 +933,7 @@ def test_variance05(xp):
922933
output = ndimage.variance(input, labels, 2)
923934
assert_almost_equal(output, xp.asarray(1.0), check_0d=False)
924935

925-
936+
@skip_xp_backends("dask.array", reason="Data-dependent output shapes")
926937
def test_variance06(xp):
927938
labels = xp.asarray([2, 2, 3, 3, 4])
928939
with np.errstate(all='ignore'):
@@ -967,6 +978,9 @@ def test_standard_deviation04(xp):
967978
assert_almost_equal(output, xp.asarray(0.5), check_0d=False)
968979

969980

981+
# dask.array is maybe due to failed conversion to numpy?
982+
# array-api-strict should've caught use of non array API functions I think
983+
@skip_xp_backends("dask.array", reason="conjugate called on dask.array which doesn't exist")
970984
def test_standard_deviation05(xp):
971985
labels = xp.asarray([2, 2, 3])
972986
for type in types:
@@ -976,6 +990,7 @@ def test_standard_deviation05(xp):
976990
assert_almost_equal(output, xp.asarray(1.0), check_0d=False)
977991

978992

993+
@skip_xp_backends("dask.array", reason="data-dependent output shapes")
979994
def test_standard_deviation06(xp):
980995
labels = xp.asarray([2, 2, 3, 3, 4])
981996
with np.errstate(all='ignore'):
@@ -988,6 +1003,7 @@ def test_standard_deviation06(xp):
9881003
assert_array_almost_equal(output, xp.asarray([1.0, 1.0, 0.0]))
9891004

9901005

1006+
@skip_xp_backends("dask.array", reason="data-dependent output shapes")
9911007
def test_standard_deviation07(xp):
9921008
labels = xp.asarray([1])
9931009
with np.errstate(all='ignore'):
@@ -1140,7 +1156,7 @@ def test_maximum_position06(xp):
11401156
assert output[0] == (0, 0)
11411157
assert output[1] == (1, 1)
11421158

1143-
1159+
@skip_xp_backends("dask.array", reason="crash in dask.array searchsorted")
11441160
def test_maximum_position07(xp):
11451161
# Test float labels
11461162
if is_torch(xp):
@@ -1158,6 +1174,7 @@ def test_maximum_position07(xp):
11581174
assert output[1] == (0, 3)
11591175

11601176

1177+
@skip_xp_backends("dask.array", reason="dask wrong answer")
11611178
def test_extrema01(xp):
11621179
labels = np.asarray([1, 0], dtype=bool)
11631180
labels = xp.asarray(labels)
@@ -1174,6 +1191,7 @@ def test_extrema01(xp):
11741191
assert output1 == (output2, output3, output4, output5)
11751192

11761193

1194+
@skip_xp_backends("dask.array", reason="dask wrong answer")
11771195
def test_extrema02(xp):
11781196
labels = xp.asarray([1, 2])
11791197
for type in types:
@@ -1298,6 +1316,7 @@ def test_center_of_mass06(xp):
12981316
assert output == expected
12991317

13001318

1319+
@skip_xp_backends("dask.array", reason="wrong output shape")
13011320
def test_center_of_mass07(xp):
13021321
labels = xp.asarray([1, 0])
13031322
expected = (0.5, 0.0)
@@ -1307,6 +1326,7 @@ def test_center_of_mass07(xp):
13071326
assert output == expected
13081327

13091328

1329+
@skip_xp_backends("dask.array", reason="wrong output shape")
13101330
def test_center_of_mass08(xp):
13111331
labels = xp.asarray([1, 2])
13121332
expected = (0.5, 1.0)
@@ -1316,6 +1336,7 @@ def test_center_of_mass08(xp):
13161336
assert output == expected
13171337

13181338

1339+
@skip_xp_backends("dask.array", reason="data-dependent output shapes")
13191340
def test_center_of_mass09(xp):
13201341
labels = xp.asarray((1, 2))
13211342
expected = xp.asarray([(0.5, 0.0), (0.5, 1.0)], dtype=xp.float64)
@@ -1353,6 +1374,7 @@ def test_histogram03(xp):
13531374
assert_array_almost_equal(output[1], expected2)
13541375

13551376

1377+
@skip_xp_backends("dask.array", reason="data-dependent output shapes")
13561378
def test_stat_funcs_2d(xp):
13571379
a = xp.asarray([[5, 6, 0, 0, 0], [8, 9, 0, 0, 0], [0, 0, 0, 3, 5]])
13581380
lbl = xp.asarray([[1, 1, 0, 0, 0], [1, 1, 0, 0, 0], [0, 0, 0, 2, 2]])

scipy/ndimage/tests/test_morphology.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
skip_xp_backends(cpu_only=True, exceptions=['cupy', 'jax.numpy'],)]
1919

2020

21+
@skip_xp_backends('dask.array',
22+
reason="Dask.array gets wrong results here. "
23+
"Some tests can pass when creating input array from list of ones"
24+
"instead of xp.ones, so maybe something is getting corrupted here."
25+
)
2126
class TestNdimageMorphology:
2227

2328
@xfail_xp_backends('cupy', reason='CuPy does not have distance_transform_bf.')

0 commit comments

Comments
 (0)