Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion xarray/core/arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class SupportsArithmetic:
numbers.Number,
bytes,
str,
) + dask_array_type
dask_array_type,
)

def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
from .computation import apply_ufunc
Expand Down
62 changes: 0 additions & 62 deletions xarray/core/dask_array_compat.py

This file was deleted.

10 changes: 6 additions & 4 deletions xarray/core/duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
from numpy import take, tensordot, transpose, unravel_index # noqa
from numpy import where as _where

from . import dask_array_compat, dask_array_ops, dtypes, npcompat, nputils
from . import dask_array_ops, dtypes, npcompat, nputils
from .nputils import nanfirst, nanlast
from .pycompat import cupy_array_type, dask_array_type, is_duck_dask_array
from .pycompat import cupy_array_type, is_duck_dask_array
from .utils import is_duck_array

try:
Expand Down Expand Up @@ -113,7 +113,7 @@ def isnull(data):
return zeros_like(data, dtype=bool)
else:
# at this point, array should have dtype=object
if isinstance(data, (np.ndarray, dask_array_type)):
if isinstance(data, np.ndarray):
return pandas_isnull(data)
else:
# Not reachable yet, but intended for use with other duck array
Expand Down Expand Up @@ -631,7 +631,9 @@ def sliding_window_view(array, window_shape, axis):
The rolling dimension will be placed at the last dimension.
"""
if is_duck_dask_array(array):
return dask_array_compat.sliding_window_view(array, window_shape, axis)
import dask.array as da

return da.lib.stride_tricks.sliding_window_view(array, window_shape, axis)
else:
return npcompat.sliding_window_view(array, window_shape, axis)

Expand Down
23 changes: 4 additions & 19 deletions xarray/core/nanops.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@

from . import dtypes, nputils, utils
from .duck_array_ops import count, fillna, isnull, where, where_method
from .pycompat import dask_array_type

try:
import dask.array as dask_array

from . import dask_array_compat
except ImportError:
dask_array = None # type: ignore[assignment]
dask_array_compat = None # type: ignore[assignment]


def _maybe_null_out(result, axis, mask, min_count=1):
Expand Down Expand Up @@ -65,34 +56,30 @@ def nanmin(a, axis=None, out=None):
if a.dtype.kind == "O":
return _nan_minmax_object("min", dtypes.get_pos_infinity(a.dtype), a, axis)

module = dask_array if isinstance(a, dask_array_type) else nputils
return module.nanmin(a, axis=axis)
return nputils.nanmin(a, axis=axis)


def nanmax(a, axis=None, out=None):
if a.dtype.kind == "O":
return _nan_minmax_object("max", dtypes.get_neg_infinity(a.dtype), a, axis)

module = dask_array if isinstance(a, dask_array_type) else nputils
return module.nanmax(a, axis=axis)
return nputils.nanmax(a, axis=axis)


def nanargmin(a, axis=None):
if a.dtype.kind == "O":
fill_value = dtypes.get_pos_infinity(a.dtype)
return _nan_argminmax_object("argmin", fill_value, a, axis=axis)

module = dask_array if isinstance(a, dask_array_type) else nputils
return module.nanargmin(a, axis=axis)
return nputils.nanargmin(a, axis=axis)


def nanargmax(a, axis=None):
if a.dtype.kind == "O":
fill_value = dtypes.get_neg_infinity(a.dtype)
return _nan_argminmax_object("argmax", fill_value, a, axis=axis)

module = dask_array if isinstance(a, dask_array_type) else nputils
return module.nanargmax(a, axis=axis)
return nputils.nanargmax(a, axis=axis)


def nansum(a, axis=None, dtype=None, out=None, min_count=None):
Expand Down Expand Up @@ -128,8 +115,6 @@ def nanmean(a, axis=None, dtype=None, out=None):
warnings.filterwarnings(
"ignore", r"Mean of empty slice", category=RuntimeWarning
)
if isinstance(a, dask_array_type):
return dask_array.nanmean(a, axis=axis, dtype=dtype)

return np.nanmean(a, axis=axis, dtype=dtype)

Expand Down
13 changes: 4 additions & 9 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
from .pycompat import (
DuckArrayModule,
cupy_array_type,
dask_array_type,
integer_types,
is_duck_dask_array,
sparse_array_type,
Expand All @@ -59,13 +58,9 @@
)

NON_NUMPY_SUPPORTED_ARRAY_TYPES = (
(
indexing.ExplicitlyIndexed,
pd.Index,
)
+ dask_array_type
+ cupy_array_type
)
indexing.ExplicitlyIndexed,
pd.Index,
) + cupy_array_type
# https://github.com/python/mypy/issues/224
BASIC_INDEXING_TYPES = integer_types + (slice,)

Expand Down Expand Up @@ -1150,7 +1145,7 @@ def to_numpy(self) -> np.ndarray:
data = self.data

# TODO first attempt to call .to_numpy() once some libraries implement it
if isinstance(data, dask_array_type):
if hasattr(data, "chunks"):
data = data.compute()
if isinstance(data, cupy_array_type):
data = data.get()
Expand Down