Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dask/array/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)
from .numpy_compat import _numpy_120
from .ufunc import greater_equal, rint
from .utils import AxisError, meta_from_array
from .utils import meta_from_array
from .wrap import empty, full, ones, zeros


Expand Down Expand Up @@ -626,7 +626,7 @@ def _axis_fmt(axis, name, ndim):
t = ndim + axis
if t < 0:
msg = "{}: axis {} is out of bounds for array of dimension {}"
raise AxisError(msg.format(name, axis, ndim))
raise np.AxisError(msg.format(name, axis, ndim))
axis = t
return axis

Expand Down
6 changes: 3 additions & 3 deletions dask/array/tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import dask
import dask.array as da
from dask.array.core import normalize_chunks
from dask.array.utils import AxisError, assert_eq, same_keys
from dask.array.utils import assert_eq, same_keys


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

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

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

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

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

cupy = pytest.importorskip("cupy")

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

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

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

v = cupy.arange(4 * 5 * 6).reshape((4, 5, 6))
Expand Down
14 changes: 7 additions & 7 deletions dask/array/tests/test_routines.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
np = pytest.importorskip("numpy")

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


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

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

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


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

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

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

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

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

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


Expand Down
24 changes: 15 additions & 9 deletions dask/array/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
from ..utils import has_keyword, is_arraylike, is_cupy_type
from .core import Array

try:
AxisError = np.AxisError
except AttributeError:
try:
np.array([0]).sum(axis=5)
except Exception as e:
AxisError = type(e)


def normalize_to_array(x):
if is_cupy_type(x):
Expand Down Expand Up @@ -462,7 +454,7 @@ def validate_axis(axis, ndim):
if not isinstance(axis, numbers.Integral):
raise TypeError("Axis value must be an integer, got %s" % axis)
if axis < -ndim or axis >= ndim:
raise AxisError(
raise np.AxisError(
"Axis %d is out of bounds for array of dimension %d" % (axis, ndim)
)
if axis < 0:
Expand Down Expand Up @@ -530,3 +522,17 @@ def scipy_linalg_safe(func_name, *args, **kwargs):

def solve_triangular_safe(a, b, lower=False):
return scipy_linalg_safe("solve_triangular", a, b, lower=lower)


def __getattr__(name):
# Can't use the @_deprecated decorator as it would not work on `except AxisError`
if name == "AxisError":
warnings.warn(
"AxisError was deprecated after version 2021.10.0 and will be removed in a "
"future release. Please use numpy.AxisError instead.",
category=FutureWarning,
stacklevel=2,
)
return np.AxisError
else:
raise AttributeError(f"module {__name__} has no attribute {name}")
10 changes: 5 additions & 5 deletions dask/dataframe/tests/test_groupby.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import collections
import operator
import warnings
from operator import methodcaller

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -977,7 +977,7 @@ def test_aggregate_build_agg_args__reuse_of_intermediates():
assert len(with_mean_finalizers) == len(with_mean_spec)


def test_aggregate__dask():
def test_aggregate_dask():
dask_holder = collections.namedtuple("dask_holder", ["dask"])
get_agg_dask = lambda obj: dask_holder(
{k: v for (k, v) in obj.dask.items() if k[0].startswith("aggregate")}
Expand Down Expand Up @@ -2438,7 +2438,7 @@ def test_groupby_empty_partitions_with_rows_operation(operation):
columns=["A", "B"],
)

caller = methodcaller(operation, 1)
caller = operator.methodcaller(operation, 1)
expected = caller(df.groupby("A")["B"])
ddf = dd.from_pandas(df, npartitions=3)
actual = caller(ddf.groupby("A")["B"])
Expand All @@ -2462,7 +2462,7 @@ def test_groupby_with_row_operations(operation):
columns=["A", "B"],
)

caller = methodcaller(operation)
caller = operator.methodcaller(operation)
expected = caller(df.groupby("A")["B"])
ddf = dd.from_pandas(df, npartitions=3)
actual = caller(ddf.groupby("A")["B"])
Expand All @@ -2486,7 +2486,7 @@ def test_groupby_multi_index_with_row_operations(operation):
columns=["A", "B"],
)

caller = methodcaller(operation)
caller = operator.methodcaller(operation)
expected = caller(df.groupby(["A", df["A"].eq("a1")])["B"])
ddf = dd.from_pandas(df, npartitions=3)
actual = caller(ddf.groupby(["A", ddf["A"].eq("a1")])["B"])
Expand Down
27 changes: 12 additions & 15 deletions dask/tests/test_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def test_f():
assert L == [1] * 20


@pytest.mark.flaky(reruns=10, reruns_delay=5)
@pytest.mark.slow
def test_interrupt():
# Windows implements `queue.get` using polling,
# which means we can set an exception to interrupt the call to `get`.
Expand All @@ -162,20 +162,17 @@ def test_interrupt():
def interrupt_main():
signal.pthread_kill(main_thread, signal.SIGINT)

def long_task():
sleep(5)

dsk = {("x", i): (long_task,) for i in range(20)}
# 7 seconds is is how long the test will take when you factor in teardown.
# Don't set it too short or the test will become flaky on non-performing CI
dsk = {("x", i): (sleep, 7) for i in range(20)}
dsk["x"] = (len, list(dsk.keys()))
try:
interrupter = threading.Timer(0.5, interrupt_main)
interrupter.start()
start = time()

# 3 seconds is how long the test will take without teardown
interrupter = threading.Timer(3, interrupt_main)
interrupter.start()

start = time()
with pytest.raises(KeyboardInterrupt):
get(dsk, "x")
except KeyboardInterrupt:
pass
except Exception:
assert False, "Failed to interrupt"
stop = time()
if stop - start > 4:
assert False, "Failed to interrupt"
assert stop < start + 6
13 changes: 13 additions & 0 deletions dask/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ def test_itemgetter():
assert g2(data) == 2
assert g2.index == 1

assert itemgetter(1) == itemgetter(1)
assert itemgetter(1) != itemgetter(2)
assert itemgetter(1) != 123


def test_partial_by_order():
assert partial_by_order(5, function=operator.add, other=[(1, 20)]) == 25
Expand Down Expand Up @@ -720,6 +724,15 @@ def foo():
assert foo() == "bar"


def test_deprecated_after_version():
@_deprecated(after_version="1.2.3")
def foo():
return "bar"

with pytest.warns(FutureWarning, match="deprecated after version 1.2.3"):
assert foo() == "bar"


def test_deprecated_category():
@_deprecated(category=DeprecationWarning)
def foo():
Expand Down
Loading