From 117dde93905e6785748835c85bf081e389ab1635 Mon Sep 17 00:00:00 2001 From: Anton Volkov Date: Sun, 11 Oct 2026 13:46:25 +0200 Subject: [PATCH] Gate median empty kept-dim tests on numpy>=2.5.4 NumPy 2.5.4 fixed the tuple-axis reduction of median and nanmedian when a kept dimension has size 0, so the tests now require it via with_requires and compare against NumPy unconditionally instead of using an inline version check with a hardcoded result shape. --- dpnp/tests/test_nanfunctions.py | 13 +++++-------- dpnp/tests/test_statistics.py | 13 +++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/dpnp/tests/test_nanfunctions.py b/dpnp/tests/test_nanfunctions.py index 354fecaeb951..810ac9b61afa 100644 --- a/dpnp/tests/test_nanfunctions.py +++ b/dpnp/tests/test_nanfunctions.py @@ -413,19 +413,16 @@ def test_empty(self, axis, shape): expected = numpy.nanmedian(a, axis=axis) assert_dtype_allclose(result, expected) + @with_requires("numpy>=2.5.4") @pytest.mark.usefixtures("suppress_mean_empty_slice_numpy_warnings") - @pytest.mark.parametrize( - "keepdims, out_shape", [(False, (0,)), (True, (0, 1, 1))] - ) - def test_empty_kept_dim(self, keepdims, out_shape): + @pytest.mark.parametrize("keepdims", [False, True]) + def test_empty_kept_dim(self, keepdims): a = numpy.empty((0, 3, 4)) ia = dpnp.array(a) result = dpnp.nanmedian(ia, axis=(1, 2), keepdims=keepdims) - assert result.shape == out_shape - if numpy_version() >= "2.5.4": - expected = numpy.nanmedian(a, axis=(1, 2), keepdims=keepdims) - assert_dtype_allclose(result, expected) + expected = numpy.nanmedian(a, axis=(1, 2), keepdims=keepdims) + assert_dtype_allclose(result, expected) @pytest.mark.usefixtures("suppress_mean_empty_slice_numpy_warnings") @pytest.mark.parametrize( diff --git a/dpnp/tests/test_statistics.py b/dpnp/tests/test_statistics.py index 0c475e6fbb31..3d5387d3de39 100644 --- a/dpnp/tests/test_statistics.py +++ b/dpnp/tests/test_statistics.py @@ -944,19 +944,16 @@ def test_empty(self, axis, shape): expected = numpy.median(a, axis=axis) assert_dtype_allclose(result, expected) + @with_requires("numpy>=2.5.4") @pytest.mark.usefixtures("suppress_mean_empty_slice_numpy_warnings") - @pytest.mark.parametrize( - "keepdims, out_shape", [(False, (0,)), (True, (0, 1, 1))] - ) - def test_empty_kept_dim(self, keepdims, out_shape): + @pytest.mark.parametrize("keepdims", [False, True]) + def test_empty_kept_dim(self, keepdims): a = numpy.empty((0, 3, 4)) ia = dpnp.array(a) result = dpnp.median(ia, axis=(1, 2), keepdims=keepdims) - assert result.shape == out_shape - if numpy_version() >= "2.5.4": - expected = numpy.median(a, axis=(1, 2), keepdims=keepdims) - assert_dtype_allclose(result, expected) + expected = numpy.median(a, axis=(1, 2), keepdims=keepdims) + assert_dtype_allclose(result, expected) @pytest.mark.parametrize("dtype", get_all_dtypes()) @pytest.mark.parametrize(