Skip to content

Commit d33febb

Browse files
authored
test fixes (#21)
1 parent 8f36e4e commit d33febb

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

scipy/_lib/tests/test__util.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from contextlib import nullcontext
12
from multiprocessing import Pool
23
from multiprocessing.pool import Pool as PWL
34
import re
@@ -12,8 +13,8 @@
1213
from hypothesis import given, strategies, reproduce_failure # noqa: F401
1314
from scipy.conftest import skip_xp_invalid_arg
1415

15-
from scipy._lib._array_api import (xp_assert_equal, xp_assert_close, is_numpy,
16-
is_array_api_strict)
16+
from scipy._lib._array_api import (xp_assert_equal, xp_assert_close, is_jax,
17+
is_numpy, is_array_api_strict)
1718
from scipy._lib._lazy_testing import lazy_xp_function
1819
from scipy._lib._util import (_aligned_zeros, check_random_state, MapWrapper,
1920
getfullargspec_no_self, FullArgSpec,
@@ -385,19 +386,24 @@ def test_array_api_lazy(self, xp):
385386
# Lazy arrays don't support "omit" and "raise" policies
386387
# TODO test that we're emitting a user-friendly error message.
387388
# Blocked by https://github.com/data-apis/array-api-compat/pull/228
388-
with pytest.raises(TypeError):
389+
390+
# note: dask doesn't raise here since there are no nans in x
391+
error_ctx = pytest.raises(TypeError) if is_jax(xp) else nullcontext()
392+
with error_ctx:
389393
_contains_nan(x, "omit")
390-
with pytest.raises(TypeError):
394+
with error_ctx:
391395
_contains_nan(x, "raise")
392396

393397
x = xpx.at(x)[1, 2, 1].set(np.nan)
394398

395399
xp_assert_equal(_contains_nan(x), xp.asarray(True))
396400
xp_assert_equal(_contains_nan(x, "propagate"), xp.asarray(True))
397401
xp_assert_equal(_contains_nan(x, "omit", xp_omit_okay=True), xp.asarray(True))
398-
with pytest.raises(TypeError):
402+
# dask raises ValueError (from in the scipy code)
403+
# jax raises a tracingerror (subclass of typeerror)
404+
with pytest.raises((TypeError, ValueError)):
399405
_contains_nan(x, "omit")
400-
with pytest.raises(TypeError):
406+
with pytest.raises((TypeError, ValueError)):
401407
_contains_nan(x, "raise")
402408

403409

scipy/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def skip_or_xfail_xp_backends(request: pytest.FixtureRequest,
398398
for d in xp.empty(0).devices():
399399
if 'cpu' not in d.device_kind:
400400
skip_or_xfail(reason=reason)
401-
elif xp.__name__ == 'dask.array':
401+
elif xp.__name__ == 'dask.array' and 'dask.array' not in exceptions:
402402
if xp_device(xp.empty(0)) != 'cpu':
403403
skip_or_xfail(reason=reason)
404404

scipy/integrate/tests/test_cubature.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ def test_break_points(self, problem, rule, rtol, atol, xp):
973973
)
974974
@skip_xp_backends(
975975
"dask.array",
976-
reasons=["transforms make use of boolean index assignment"],
976+
reason="transforms make use of boolean index assignment"
977977
)
978978
@pytest.mark.parametrize("problem", [
979979
(
@@ -1127,7 +1127,7 @@ def test_infinite_limits(self, problem, rule, rtol, atol, xp):
11271127
)
11281128
@skip_xp_backends(
11291129
"dask.array",
1130-
reasons=["transforms make use of boolean index assignment"],
1130+
reason="transforms make use of boolean index assignment"
11311131
)
11321132
@pytest.mark.parametrize("problem", [
11331133
(
@@ -1338,7 +1338,7 @@ def test_genz_malik_1d_raises_error(self, xp):
13381338
)
13391339
@skip_xp_backends(
13401340
"dask.array",
1341-
reasons=["transforms make use of boolean index assignment"],
1341+
reason="transforms make use of boolean index assignment"
13421342
)
13431343
class TestTransformations:
13441344
@pytest.mark.parametrize(("a", "b", "points"), [

scipy/ndimage/tests/test_filters.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,7 @@ def test_gaussian_radius_invalid(xp):
26472647

26482648

26492649
@skip_xp_backends("jax.numpy", reason="output array is read-only")
2650+
@skip_xp_backends("dask.array", reason="wrong answer")
26502651
class TestThreading:
26512652
def check_func_thread(self, n, fun, args, out):
26522653
from threading import Thread

scipy/signal/tests/test_windows.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
from scipy.fft import fft
1010
from scipy.signal import windows, get_window, resample
1111
from scipy._lib._array_api import (
12-
xp_assert_close, xp_assert_equal, array_namespace, is_torch, is_jax, is_cupy,
13-
assert_array_almost_equal, SCIPY_DEVICE,
12+
xp_assert_close, xp_assert_equal, array_namespace, is_dask,
13+
is_torch, is_jax, is_cupy, assert_array_almost_equal, SCIPY_DEVICE,
1414
)
1515

1616
skip_xp_backends = pytest.mark.skip_xp_backends
@@ -256,6 +256,7 @@ def test_basic(self, xp):
256256

257257

258258
@skip_xp_backends('jax.numpy', reason='item assignment')
259+
@skip_xp_backends('dask.array', reason='data-dependent output shapes')
259260
class TestChebWin:
260261

261262
def test_basic(self, xp):
@@ -778,6 +779,7 @@ def test_boxcar(self, xp):
778779
xp_assert_equal(w, xp.ones_like(w))
779780

780781
@skip_xp_backends('jax.numpy', reason='item assignment')
782+
@skip_xp_backends('dask.array', reason='data-dependent output shapes')
781783
def test_cheb_odd(self, xp):
782784
with suppress_warnings() as sup:
783785
sup.filter(UserWarning, "This window is not suitable")
@@ -787,6 +789,7 @@ def test_cheb_odd(self, xp):
787789
)
788790

789791
@skip_xp_backends('jax.numpy', reason='item assignment')
792+
@skip_xp_backends('dask.array', reason='data-dependent output shapes')
790793
def test_cheb_even(self, xp):
791794
with suppress_warnings() as sup:
792795
sup.filter(UserWarning, "This window is not suitable")
@@ -854,6 +857,11 @@ def test_windowfunc_basics(xp):
854857
window = getattr(windows, window_name)
855858
if is_jax(xp) and window_name in ['taylor', 'chebwin']:
856859
pytest.skip(reason=f'{window_name = }: item assignment')
860+
if is_dask(xp):
861+
# https://github.com/dask/dask/issues/2620
862+
pytest.skip(
863+
reason="dask doesn't support FFT along axis containing multiple chunks"
864+
)
857865
if window_name in ['dpss']:
858866
if is_cupy(xp):
859867
pytest.skip(reason='dpss window is not implemented for cupy')

0 commit comments

Comments
 (0)