Skip to content

Commit

Permalink
always use dask_array_type for isinstance calls (#3787)
Browse files Browse the repository at this point in the history
* always use dask_array_type for instance checking

* update whats-new.rst
  • Loading branch information
keewis authored Feb 23, 2020
1 parent 858eba6 commit 66625c9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ New Features

Bug fixes
~~~~~~~~~
- Use ``dask_array_type`` instead of ``dask_array.Array`` for type
checking. (:issue:`3779`, :pull:`3787`)
By `Justus Magin <https://github.com/keewis>`_.

Documentation
~~~~~~~~~~~~~
Expand Down
4 changes: 3 additions & 1 deletion xarray/core/dask_array_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import numpy as np

from .pycompat import dask_array_type

try:
import dask.array as da
from dask import __version__ as dask_version
Expand Down Expand Up @@ -36,7 +38,7 @@ def meta_from_array(x, ndim=None, dtype=None):
"""
# If using x._meta, x must be a Dask Array, some libraries (e.g. zarr)
# implement a _meta attribute that are incompatible with Dask Array._meta
if hasattr(x, "_meta") and isinstance(x, da.Array):
if hasattr(x, "_meta") and isinstance(x, dask_array_type):
x = x._meta

if dtype is None and x is None:
Expand Down
6 changes: 3 additions & 3 deletions xarray/core/duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def f(*args, **kwargs):
dispatch_args = args[0]
else:
dispatch_args = args[array_args]
if any(isinstance(a, dask_array.Array) for a in dispatch_args):
if any(isinstance(a, dask_array_type) for a in dispatch_args):
try:
wrapped = getattr(dask_module, name)
except AttributeError as e:
Expand Down Expand Up @@ -190,8 +190,8 @@ def lazy_array_equiv(arr1, arr2):
return False
if (
dask_array
and isinstance(arr1, dask_array.Array)
and isinstance(arr2, dask_array.Array)
and isinstance(arr1, dask_array_type)
and isinstance(arr2, dask_array_type)
):
# GH3068
if arr1.name == arr2.name:
Expand Down

0 comments on commit 66625c9

Please sign in to comment.