Skip to content

Commit

Permalink
Fix upstream build (#10549)
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Oct 18, 2023
1 parent b4bd120 commit 51210a6
Show file tree
Hide file tree
Showing 26 changed files with 137 additions and 72 deletions.
3 changes: 2 additions & 1 deletion continuous_integration/scripts/install.sh
Expand Up @@ -30,7 +30,8 @@ if [[ ${UPSTREAM_DEV} ]]; then
git+https://github.com/dask/zict \
git+https://github.com/dask/distributed \
git+https://github.com/dask/fastparquet \
git+https://github.com/zarr-developers/zarr-python
git+https://github.com/zarr-developers/zarr-python \
git+https://github.com/PyTables/PyTables@ab565af10250922f2778204fd62b42ee12087d12 # numpy 2 support

# FIXME https://github.com/mamba-org/mamba/issues/412
# mamba uninstall --force ...
Expand Down
2 changes: 1 addition & 1 deletion dask/array/core.py
Expand Up @@ -731,7 +731,7 @@ def map_blocks(
... loc = block_info[None]['array-location'][0]
... return np.arange(loc[0], loc[1])
>>> da.map_blocks(func, chunks=((4, 4),), dtype=np.float_)
>>> da.map_blocks(func, chunks=((4, 4),), dtype=np.float64)
dask.array<func, shape=(8,), dtype=float64, chunksize=(4,), chunktype=numpy.ndarray>
>>> _.compute()
Expand Down
9 changes: 4 additions & 5 deletions dask/array/creation.py
Expand Up @@ -22,6 +22,7 @@
normalize_chunks,
stack,
)
from dask.array.numpy_compat import AxisError
from dask.array.ufunc import greater_equal, rint
from dask.array.utils import meta_from_array
from dask.array.wrap import empty, full, ones, zeros
Expand Down Expand Up @@ -693,7 +694,7 @@ def _axis_fmt(axis, name, ndim):
t = ndim + axis
if t < 0:
msg = "{}: axis {} is out of bounds for array of dimension {}"
raise np.AxisError(msg.format(name, axis, ndim))
raise AxisError(msg.format(name, axis, ndim))
axis = t
return axis

Expand Down Expand Up @@ -813,16 +814,14 @@ def pop_axes(chunks, axis1, axis2):

@derived_from(np)
def tri(N, M=None, k=0, dtype=float, chunks="auto", *, like=None):
_min_int = np.lib.twodim_base._min_int

if M is None:
M = N

chunks = normalize_chunks(chunks, shape=(N, M), dtype=dtype)

m = greater_equal(
arange(N, chunks=chunks[0][0], dtype=_min_int(0, N), like=like).reshape(1, N).T,
arange(-k, M - k, chunks=chunks[1][0], dtype=_min_int(-k, M - k), like=like),
arange(N, chunks=chunks[0][0], like=like).reshape(1, N).T,
arange(-k, M - k, chunks=chunks[1][0], like=like),
)

# Avoid making a copy if the requested type is already bool
Expand Down
20 changes: 15 additions & 5 deletions dask/array/numpy_compat.py
Expand Up @@ -12,6 +12,14 @@
_numpy_123 = _np_version >= parse_version("1.23.0")
_numpy_124 = _np_version >= parse_version("1.24.0")
_numpy_125 = _np_version.release >= (1, 25, 0)
_numpy_200 = _np_version.release >= (2, 0, 0)


if _numpy_200:
from numpy.lib.array_utils import normalize_axis_index, normalize_axis_tuple
else:
from numpy.core.numeric import normalize_axis_index # type: ignore[attr-defined]
from numpy.core.numeric import normalize_axis_tuple # type: ignore[attr-defined]


# Taken from scikit-learn:
Expand Down Expand Up @@ -135,10 +143,8 @@ def walk(self, x, index=()):
# https://github.com/numpy/numpy/blob/d9b1e32cb8ef90d6b4a47853241db2a28146a57d/numpy/core/numeric.py#L1336-L1405
@derived_from(np)
def moveaxis(a, source, destination):
source = np.core.numeric.normalize_axis_tuple(source, a.ndim, "source")
destination = np.core.numeric.normalize_axis_tuple(
destination, a.ndim, "destination"
)
source = normalize_axis_tuple(source, a.ndim, "source")
destination = normalize_axis_tuple(destination, a.ndim, "destination")
if len(source) != len(destination):
raise ValueError(
"`source` and `destination` arguments must have "
Expand All @@ -158,7 +164,7 @@ def moveaxis(a, source, destination):
# https://github.com/numpy/numpy/blob/v1.17.0/numpy/core/numeric.py#L1107-L1204
def rollaxis(a, axis, start=0):
n = a.ndim
axis = np.core.numeric.normalize_axis_index(axis, n)
axis = normalize_axis_index(axis, n)
if start < 0:
start += n
msg = "'%s' arg requires %d <= %s < %d, but %d was passed in"
Expand All @@ -181,3 +187,7 @@ def percentile(a, q, method="linear"):
return np.percentile(a, q, method=method)
else:
return np.percentile(a, q, interpolation=method)


ComplexWarning = np.exceptions.ComplexWarning if _numpy_200 else np.ComplexWarning
AxisError = np.exceptions.AxisError if _numpy_200 else np.AxisError
3 changes: 1 addition & 2 deletions dask/array/overlap.py
Expand Up @@ -10,6 +10,7 @@
from dask.array import chunk
from dask.array.core import Array, concatenate, map_blocks, unify_chunks
from dask.array.creation import empty_like, full_like
from dask.array.numpy_compat import normalize_axis_tuple
from dask.base import tokenize
from dask.highlevelgraph import HighLevelGraph
from dask.layers import ArrayOverlapLayer
Expand Down Expand Up @@ -782,8 +783,6 @@ def coerce_boundary(ndim, boundary):

@derived_from(np.lib.stride_tricks)
def sliding_window_view(x, window_shape, axis=None):
from numpy.core.numeric import normalize_axis_tuple

window_shape = tuple(window_shape) if np.iterable(window_shape) else (window_shape,)

window_shape_array = np.array(window_shape)
Expand Down
3 changes: 2 additions & 1 deletion dask/array/reductions.py
Expand Up @@ -27,6 +27,7 @@
)
from dask.array.creation import arange, diagonal
from dask.array.dispatch import divide_lookup, nannumel_lookup, numel_lookup
from dask.array.numpy_compat import ComplexWarning
from dask.array.utils import (
array_safe,
asarray_safe,
Expand Down Expand Up @@ -387,7 +388,7 @@ def partial_reduce(
else:
with contextlib.suppress(AttributeError), warnings.catch_warnings():
if name.startswith("var") or name.startswith("moment"):
warnings.simplefilter("ignore", np.ComplexWarning)
warnings.simplefilter("ignore", ComplexWarning)
meta = meta.astype(dtype)
return Array(graph, name, out_chunks, meta=meta)

Expand Down
2 changes: 1 addition & 1 deletion dask/array/routines.py
Expand Up @@ -1811,7 +1811,7 @@ def unique(ar, return_index=False, return_inverse=False, return_counts=False):


def _isin_kernel(element, test_elements, assume_unique=False):
values = np.in1d(element.ravel(), test_elements, assume_unique=assume_unique)
values = np.isin(element.ravel(), test_elements, assume_unique=assume_unique)
return values.reshape(element.shape + (1,) * test_elements.ndim)


Expand Down
8 changes: 4 additions & 4 deletions dask/array/tests/test_array_core.py
Expand Up @@ -1485,7 +1485,7 @@ def test_map_blocks_block_info_with_broadcast():
None: {
"shape": (6, 4),
"num-chunks": (2, 2),
"dtype": np.float_,
"dtype": np.float64,
"chunk-shape": (3, 2),
"array-location": [(0, 3), (0, 2)],
"chunk-location": (0, 0),
Expand All @@ -1498,7 +1498,7 @@ def test_map_blocks_block_info_with_broadcast():
None: {
"shape": (6, 4),
"num-chunks": (2, 2),
"dtype": np.float_,
"dtype": np.float64,
"chunk-shape": (3, 2),
"array-location": [(0, 3), (2, 4)],
"chunk-location": (0, 1),
Expand All @@ -1511,7 +1511,7 @@ def test_map_blocks_block_info_with_broadcast():
None: {
"shape": (6, 4),
"num-chunks": (2, 2),
"dtype": np.float_,
"dtype": np.float64,
"chunk-shape": (3, 2),
"array-location": [(3, 6), (0, 2)],
"chunk-location": (1, 0),
Expand All @@ -1524,7 +1524,7 @@ def test_map_blocks_block_info_with_broadcast():
None: {
"shape": (6, 4),
"num-chunks": (2, 2),
"dtype": np.float_,
"dtype": np.float64,
"chunk-shape": (3, 2),
"array-location": [(3, 6), (2, 4)],
"chunk-location": (1, 1),
Expand Down
5 changes: 3 additions & 2 deletions dask/array/tests/test_creation.py
Expand Up @@ -11,6 +11,7 @@
import dask
import dask.array as da
from dask.array.core import normalize_chunks
from dask.array.numpy_compat import AxisError
from dask.array.utils import assert_eq, same_keys


Expand Down Expand Up @@ -521,10 +522,10 @@ def test_diagonal():
with pytest.raises(ValueError):
da.diagonal(v, axis1=0, axis2=0)

with pytest.raises(np.AxisError):
with pytest.raises(AxisError):
da.diagonal(v, axis1=-4)

with pytest.raises(np.AxisError):
with pytest.raises(AxisError):
da.diagonal(v, axis2=-4)

v = np.arange(4 * 5 * 6).reshape((4, 5, 6))
Expand Down
5 changes: 3 additions & 2 deletions dask/array/tests/test_cupy_creation.py
Expand Up @@ -7,6 +7,7 @@

import dask.array as da
from dask import config
from dask.array.numpy_compat import AxisError
from dask.array.utils import assert_eq

cupy = pytest.importorskip("cupy")
Expand Down Expand Up @@ -43,10 +44,10 @@ def test_diagonal():
with pytest.raises(ValueError):
da.diagonal(v, axis1=0, axis2=0)

with pytest.raises(np.AxisError):
with pytest.raises(AxisError):
da.diagonal(v, axis1=-4)

with pytest.raises(np.AxisError):
with pytest.raises(AxisError):
da.diagonal(v, axis2=-4)

v = cupy.arange(4 * 5 * 6).reshape((4, 5, 6))
Expand Down
7 changes: 7 additions & 0 deletions dask/array/tests/test_image.py
Expand Up @@ -5,6 +5,13 @@

import pytest

from dask.array.numpy_compat import _numpy_200

if _numpy_200:
# `import skimage` fails with `numpy=2`
# xref https://github.com/scikit-image/scikit-image/pull/7118
pytest.skip("skimage doesn't yet support numpy=2", allow_module_level=True)

pytest.importorskip("skimage")
import numpy as np
from skimage.io import imsave
Expand Down
5 changes: 5 additions & 0 deletions dask/array/tests/test_linalg.py
Expand Up @@ -4,6 +4,11 @@

import pytest

from dask.array.numpy_compat import _numpy_200

if _numpy_200:
pytest.skip("scipy doesn't yet support numpy=2", allow_module_level=True)

pytest.importorskip("numpy")
pytest.importorskip("scipy")

Expand Down
7 changes: 4 additions & 3 deletions dask/array/tests/test_masked.py
Expand Up @@ -9,9 +9,10 @@
import pytest

import dask.array as da
from dask.array.numpy_compat import _numpy_123
from dask.array.numpy_compat import ComplexWarning, _numpy_123
from dask.array.utils import assert_eq
from dask.base import tokenize
from dask.utils import typename

pytest.importorskip("dask.array.ma")

Expand Down Expand Up @@ -123,7 +124,7 @@ def test_tensordot():


@pytest.mark.parametrize("func", functions)
@pytest.mark.filterwarnings("ignore::numpy.ComplexWarning") # abs() in assert_eq
@pytest.mark.filterwarnings(f"ignore::{typename(ComplexWarning)}") # abs() in assert_eq
def test_mixed_concatenate(func):
rng = da.random.default_rng()
x = rng.random((2, 3, 4), chunks=(1, 2, 2))
Expand All @@ -141,7 +142,7 @@ def test_mixed_concatenate(func):


@pytest.mark.parametrize("func", functions)
@pytest.mark.filterwarnings("ignore::numpy.ComplexWarning") # abs() in assert_eq
@pytest.mark.filterwarnings(f"ignore::{typename(ComplexWarning)}") # abs() in assert_eq
def test_mixed_random(func):
d = da.random.default_rng().random((4, 3, 4), chunks=(1, 2, 2))
d[d < 0.4] = 0
Expand Down
14 changes: 5 additions & 9 deletions dask/array/tests/test_reductions.py
Expand Up @@ -13,7 +13,7 @@

import dask.array as da
import dask.config as config
from dask.array.numpy_compat import _numpy_122
from dask.array.numpy_compat import ComplexWarning, _numpy_122
from dask.array.utils import assert_eq, same_keys
from dask.core import get_deps

Expand Down Expand Up @@ -103,9 +103,7 @@ def reduction_1d_test(da_func, darr, np_func, narr, use_dtype=True, split_every=
assert same_keys(da_func(darr), da_func(darr))
assert same_keys(da_func(darr, keepdims=True), da_func(darr, keepdims=True))
if use_dtype:
with pytest.warns(np.ComplexWarning) if np.iscomplexobj(
narr
) else does_not_warn():
with pytest.warns(ComplexWarning) if np.iscomplexobj(narr) else does_not_warn():
assert_eq(da_func(darr, dtype="f8"), np_func(narr, dtype="f8"))
assert_eq(da_func(darr, dtype="i8"), np_func(narr, dtype="i8"))
assert same_keys(da_func(darr, dtype="i8"), da_func(darr, dtype="i8"))
Expand All @@ -123,7 +121,7 @@ def reduction_1d_test(da_func, darr, np_func, narr, use_dtype=True, split_every=
@pytest.mark.parametrize("dtype", ["f4", "i4", "c8"])
def test_reductions_1D(dtype):
with warnings.catch_warnings():
warnings.simplefilter("ignore", np.ComplexWarning)
warnings.simplefilter("ignore", ComplexWarning)
x = (np.arange(5) + 1j * np.arange(5)).astype(dtype)
a = da.from_array(x, chunks=(2,))

Expand Down Expand Up @@ -167,9 +165,7 @@ def reduction_2d_test(da_func, darr, np_func, narr, use_dtype=True, split_every=
assert same_keys(da_func(darr, axis=(1, 0)), da_func(darr, axis=(1, 0)))

if use_dtype:
with pytest.warns(np.ComplexWarning) if np.iscomplexobj(
narr
) else does_not_warn():
with pytest.warns(ComplexWarning) if np.iscomplexobj(narr) else does_not_warn():
assert_eq(da_func(darr, dtype="f8"), np_func(narr, dtype="f8"))
assert_eq(da_func(darr, dtype="i8"), np_func(narr, dtype="i8"))

Expand Down Expand Up @@ -212,7 +208,7 @@ def test_reduction_errors():
@pytest.mark.parametrize("dtype", ["f4", "i4", "c8"])
def test_reductions_2D(dtype):
with warnings.catch_warnings():
warnings.simplefilter("ignore", np.ComplexWarning)
warnings.simplefilter("ignore", ComplexWarning)
x = (np.arange(1, 122) + 1j * np.arange(1, 122)).reshape((11, 11)).astype(dtype)
a = da.from_array(x, chunks=(4, 4))

Expand Down
15 changes: 7 additions & 8 deletions dask/array/tests/test_routines.py
Expand Up @@ -7,15 +7,14 @@
from numbers import Number

import pytest
from numpy import AxisError

import dask
from dask.delayed import delayed

np = pytest.importorskip("numpy")

import dask.array as da
from dask.array.numpy_compat import _numpy_123
from dask.array.numpy_compat import AxisError, _numpy_123
from dask.array.utils import assert_eq, same_keys


Expand Down Expand Up @@ -2252,10 +2251,10 @@ def test_insert():
with pytest.raises(NotImplementedError):
da.insert(a, [4, 2], -1, axis=0)

with pytest.raises(np.AxisError):
with pytest.raises(AxisError):
da.insert(a, [3], -1, axis=2)

with pytest.raises(np.AxisError):
with pytest.raises(AxisError):
da.insert(a, [3], -1, axis=-3)


Expand Down Expand Up @@ -2298,9 +2297,9 @@ def test_append():
)

# check AxisError
with pytest.raises(np.AxisError):
with pytest.raises(AxisError):
da.append(a, ((0,) * 10,) * 10, axis=2)
with pytest.raises(np.AxisError):
with pytest.raises(AxisError):
da.append(a, ((0,) * 10,) * 10, axis=-3)

# check ValueError if dimensions don't align
Expand Down Expand Up @@ -2337,10 +2336,10 @@ def test_delete():

assert_eq(np.delete(a, [4, 2], axis=0), da.delete(a, [4, 2], axis=0))

with pytest.raises(np.AxisError):
with pytest.raises(AxisError):
da.delete(a, [3], axis=2)

with pytest.raises(np.AxisError):
with pytest.raises(AxisError):
da.delete(a, [3], axis=-3)


Expand Down
5 changes: 5 additions & 0 deletions dask/array/tests/test_stats.py
Expand Up @@ -5,6 +5,11 @@
import pytest
from packaging.version import parse as parse_version

from dask.array.numpy_compat import _numpy_200

if _numpy_200:
pytest.skip("scipy doesn't yet support numpy=2", allow_module_level=True)

scipy = pytest.importorskip("scipy")
import numpy as np

Expand Down

0 comments on commit 51210a6

Please sign in to comment.