From: Antonio Valentino Date: Sat, 27 Jun 2026 09:20:06 +0000 Subject: numpy-2.4-compat Origin: https://github.com/dask/dask/commit/52a5349042acd311c1bc6637214523f0d7897899 https://github.com/dask/dask/commit/0322a6a27557c4b745f50482db59711f18e3a60f Forwarded: not-needed --- dask/array/numpy_compat.py | 1 + dask/array/reductions.py | 30 +++++++++++++++++++++++++----- dask/array/tests/test_ufunc.py | 13 +++++++++---- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/dask/array/numpy_compat.py b/dask/array/numpy_compat.py index d54cf4d..9105093 100644 --- a/dask/array/numpy_compat.py +++ b/dask/array/numpy_compat.py @@ -14,6 +14,7 @@ _np_version = Version(np.__version__) NUMPY_GE_125 = _np_version.release >= (1, 25) NUMPY_GE_200 = _np_version.release >= (2, 0) NUMPY_GE_210 = _np_version.release >= (2, 1) +NUMPY_GE_240 = _np_version.release >= (2, 4) if NUMPY_GE_200: diff --git a/dask/array/reductions.py b/dask/array/reductions.py index 49bbe14..f03bd95 100644 --- a/dask/array/reductions.py +++ b/dask/array/reductions.py @@ -1881,6 +1881,18 @@ def quantile( This works by automatically chunking the reduced axes to a single chunk if necessary and then calling ``numpy.quantile`` function across the remaining dimensions """ + if interpolation is not None: + warnings.warn( + "The `interpolation` argument to quantile was renamed to `method`.", + FutureWarning, + stacklevel=2, + ) + + if method != "linear": + raise TypeError("Cannot pass interpolation and method keywords!") + + method = interpolation + if axis is None: if any(n_blocks > 1 for n_blocks in a.numblocks): raise NotImplementedError( @@ -1908,7 +1920,6 @@ def quantile( np.quantile, q=q, method=method, - interpolation=interpolation, axis=axis, keepdims=keepdims, drop_axis=axis if not keepdims else None, @@ -1943,12 +1954,11 @@ def _custom_quantile( q, axis=None, method="linear", - interpolation=None, keepdims=False, **kwargs, ): if ( - not {method, interpolation}.issubset({"linear", None}) + method != "linear" or len(axis) != 1 or axis[0] != len(a.shape) - 1 or len(a.shape) == 1 @@ -1961,7 +1971,6 @@ def _custom_quantile( q, axis=axis, method=method, - interpolation=interpolation, keepdims=keepdims, **kwargs, ) @@ -2032,6 +2041,18 @@ def nanquantile( This works by automatically chunking the reduced axes to a single chunk and then calling ``numpy.nanquantile`` function across the remaining dimensions """ + if interpolation is not None: + warnings.warn( + "The `interpolation` argument to nanquantile was renamed to `method`.", + FutureWarning, + stacklevel=2, + ) + + if method != "linear": + raise TypeError("Cannot pass interpolation and method keywords!") + + method = interpolation + if axis is None: if any(n_blocks > 1 for n_blocks in a.numblocks): raise NotImplementedError( @@ -2059,7 +2080,6 @@ def nanquantile( _custom_quantile, q=q, method=method, - interpolation=interpolation, axis=axis, keepdims=keepdims, drop_axis=axis if not keepdims else None, diff --git a/dask/array/tests/test_ufunc.py b/dask/array/tests/test_ufunc.py index f75b16c..ef061e2 100644 --- a/dask/array/tests/test_ufunc.py +++ b/dask/array/tests/test_ufunc.py @@ -10,6 +10,7 @@ import pytest np = pytest.importorskip("numpy") import dask.array as da +from dask.array.numpy_compat import NUMPY_GE_240 from dask.array.ufunc import da_frompyfunc from dask.array.utils import assert_eq from dask.base import tokenize @@ -29,10 +30,14 @@ def test_ufunc_meta(name): assert ufunc.__name__ == name assert disclaimer in ufunc.__doc__ - assert ( - ufunc.__doc__.replace(disclaimer, "").replace(skip_test, "") - == getattr(np, name).__doc__ - ) + if not NUMPY_GE_240: + # https://github.com/numpy/numpy/issues/30095 + # ufunc inspection doesn't provide argument names, which + # breaks our docstring rewriting + assert ( + ufunc.__doc__.replace(disclaimer, "").replace(skip_test, "") + == getattr(np, name).__doc__ + ) def test_ufunc():