Skip to content

Commit cdcb3fb

Browse files
committed
simplify __array_ufunc__ check
1 parent 67d7efc commit cdcb3fb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

xarray/core/arithmetic.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .common import ImplementsArrayReduce, ImplementsDatasetReduce
1717
from .ops import IncludeCumMethods, IncludeNumpySameMethods, IncludeReduceMethods
1818
from .options import OPTIONS, _get_keep_attrs
19-
from .pycompat import dask_array_type
19+
from .pycompat import is_duck_array
2020

2121

2222
class SupportsArithmetic:
@@ -33,20 +33,21 @@ class SupportsArithmetic:
3333

3434
# TODO: allow extending this with some sort of registration system
3535
_HANDLED_TYPES = (
36-
np.ndarray,
3736
np.generic,
3837
numbers.Number,
3938
bytes,
4039
str,
41-
) + dask_array_type
40+
)
4241

4342
def __array_ufunc__(self, ufunc, method, *inputs, **kwargs):
4443
from .computation import apply_ufunc
4544

4645
# See the docstring example for numpy.lib.mixins.NDArrayOperatorsMixin.
4746
out = kwargs.get("out", ())
4847
for x in inputs + out:
49-
if not isinstance(x, self._HANDLED_TYPES + (SupportsArithmetic,)):
48+
if not is_duck_array(x) and not isinstance(
49+
x, self._HANDLED_TYPES + (SupportsArithmetic,)
50+
):
5051
return NotImplemented
5152

5253
if ufunc.signature is not None:

0 commit comments

Comments
 (0)