| 1 |
From: Antonio Valentino <[email protected]> |
| 2 |
Date: Sat, 27 Jun 2026 09:20:06 +0000 |
| 3 |
Subject: numpy-2.4-compat |
| 4 |
|
| 5 |
Origin: https://github.com/dask/dask/commit/52a5349042acd311c1bc6637214523f0d7897899 |
| 6 |
https://github.com/dask/dask/commit/0322a6a27557c4b745f50482db59711f18e3a60f |
| 7 |
Forwarded: not-needed |
| 8 |
--- |
| 9 |
dask/array/numpy_compat.py | 1 + |
| 10 |
dask/array/reductions.py | 30 +++++++++++++++++++++++++----- |
| 11 |
dask/array/tests/test_ufunc.py | 13 +++++++++---- |
| 12 |
3 files changed, 35 insertions(+), 9 deletions(-) |
| 13 |
|
| 14 |
diff --git a/dask/array/numpy_compat.py b/dask/array/numpy_compat.py |
| 15 |
index d54cf4d..9105093 100644 |
| 16 |
--- a/dask/array/numpy_compat.py |
| 17 |
+++ b/dask/array/numpy_compat.py |
| 18 |
@@ -14,6 +14,7 @@ _np_version = Version(np.__version__) |
| 19 |
NUMPY_GE_125 = _np_version.release >= (1, 25) |
| 20 |
NUMPY_GE_200 = _np_version.release >= (2, 0) |
| 21 |
NUMPY_GE_210 = _np_version.release >= (2, 1) |
| 22 |
+NUMPY_GE_240 = _np_version.release >= (2, 4) |
| 23 |
|
| 24 |
|
| 25 |
if NUMPY_GE_200: |
| 26 |
diff --git a/dask/array/reductions.py b/dask/array/reductions.py |
| 27 |
index 49bbe14..f03bd95 100644 |
| 28 |
--- a/dask/array/reductions.py |
| 29 |
+++ b/dask/array/reductions.py |
| 30 |
@@ -1881,6 +1881,18 @@ def quantile( |
| 31 |
This works by automatically chunking the reduced axes to a single chunk if necessary |
| 32 |
and then calling ``numpy.quantile`` function across the remaining dimensions |
| 33 |
""" |
| 34 |
+ if interpolation is not None: |
| 35 |
+ warnings.warn( |
| 36 |
+ "The `interpolation` argument to quantile was renamed to `method`.", |
| 37 |
+ FutureWarning, |
| 38 |
+ stacklevel=2, |
| 39 |
+ ) |
| 40 |
+ |
| 41 |
+ if method != "linear": |
| 42 |
+ raise TypeError("Cannot pass interpolation and method keywords!") |
| 43 |
+ |
| 44 |
+ method = interpolation |
| 45 |
+ |
| 46 |
if axis is None: |
| 47 |
if any(n_blocks > 1 for n_blocks in a.numblocks): |
| 48 |
raise NotImplementedError( |
| 49 |
@@ -1908,7 +1920,6 @@ def quantile( |
| 50 |
np.quantile, |
| 51 |
q=q, |
| 52 |
method=method, |
| 53 |
- interpolation=interpolation, |
| 54 |
axis=axis, |
| 55 |
keepdims=keepdims, |
| 56 |
drop_axis=axis if not keepdims else None, |
| 57 |
@@ -1943,12 +1954,11 @@ def _custom_quantile( |
| 58 |
q, |
| 59 |
axis=None, |
| 60 |
method="linear", |
| 61 |
- interpolation=None, |
| 62 |
keepdims=False, |
| 63 |
**kwargs, |
| 64 |
): |
| 65 |
if ( |
| 66 |
- not {method, interpolation}.issubset({"linear", None}) |
| 67 |
+ method != "linear" |
| 68 |
or len(axis) != 1 |
| 69 |
or axis[0] != len(a.shape) - 1 |
| 70 |
or len(a.shape) == 1 |
| 71 |
@@ -1961,7 +1971,6 @@ def _custom_quantile( |
| 72 |
q, |
| 73 |
axis=axis, |
| 74 |
method=method, |
| 75 |
- interpolation=interpolation, |
| 76 |
keepdims=keepdims, |
| 77 |
**kwargs, |
| 78 |
) |
| 79 |
@@ -2032,6 +2041,18 @@ def nanquantile( |
| 80 |
This works by automatically chunking the reduced axes to a single chunk |
| 81 |
and then calling ``numpy.nanquantile`` function across the remaining dimensions |
| 82 |
""" |
| 83 |
+ if interpolation is not None: |
| 84 |
+ warnings.warn( |
| 85 |
+ "The `interpolation` argument to nanquantile was renamed to `method`.", |
| 86 |
+ FutureWarning, |
| 87 |
+ stacklevel=2, |
| 88 |
+ ) |
| 89 |
+ |
| 90 |
+ if method != "linear": |
| 91 |
+ raise TypeError("Cannot pass interpolation and method keywords!") |
| 92 |
+ |
| 93 |
+ method = interpolation |
| 94 |
+ |
| 95 |
if axis is None: |
| 96 |
if any(n_blocks > 1 for n_blocks in a.numblocks): |
| 97 |
raise NotImplementedError( |
| 98 |
@@ -2059,7 +2080,6 @@ def nanquantile( |
| 99 |
_custom_quantile, |
| 100 |
q=q, |
| 101 |
method=method, |
| 102 |
- interpolation=interpolation, |
| 103 |
axis=axis, |
| 104 |
keepdims=keepdims, |
| 105 |
drop_axis=axis if not keepdims else None, |
| 106 |
diff --git a/dask/array/tests/test_ufunc.py b/dask/array/tests/test_ufunc.py |
| 107 |
index f75b16c..ef061e2 100644 |
| 108 |
--- a/dask/array/tests/test_ufunc.py |
| 109 |
+++ b/dask/array/tests/test_ufunc.py |
| 110 |
@@ -10,6 +10,7 @@ import pytest |
| 111 |
np = pytest.importorskip("numpy") |
| 112 |
|
| 113 |
import dask.array as da |
| 114 |
+from dask.array.numpy_compat import NUMPY_GE_240 |
| 115 |
from dask.array.ufunc import da_frompyfunc |
| 116 |
from dask.array.utils import assert_eq |
| 117 |
from dask.base import tokenize |
| 118 |
@@ -29,10 +30,14 @@ def test_ufunc_meta(name): |
| 119 |
assert ufunc.__name__ == name |
| 120 |
assert disclaimer in ufunc.__doc__ |
| 121 |
|
| 122 |
- assert ( |
| 123 |
- ufunc.__doc__.replace(disclaimer, "").replace(skip_test, "") |
| 124 |
- == getattr(np, name).__doc__ |
| 125 |
- ) |
| 126 |
+ if not NUMPY_GE_240: |
| 127 |
+ # https://github.com/numpy/numpy/issues/30095 |
| 128 |
+ # ufunc inspection doesn't provide argument names, which |
| 129 |
+ # breaks our docstring rewriting |
| 130 |
+ assert ( |
| 131 |
+ ufunc.__doc__.replace(disclaimer, "").replace(skip_test, "") |
| 132 |
+ == getattr(np, name).__doc__ |
| 133 |
+ ) |
| 134 |
|
| 135 |
|
| 136 |
def test_ufunc(): |