Skip to content

is_dask_collection: micro optimization #6107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2021
Merged
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
24 changes: 12 additions & 12 deletions xarray/core/pycompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,19 @@ def __init__(self, mod):
self.available = duck_array_module is not None


dsk = DuckArrayModule("dask")
dask_version = dsk.version
dask_array_type = dsk.type

sp = DuckArrayModule("sparse")
sparse_array_type = sp.type
sparse_version = sp.version

cupy_array_type = DuckArrayModule("cupy").type


def is_dask_collection(x):
if DuckArrayModule("dask").available:
if dsk.available:
from dask.base import is_dask_collection

return is_dask_collection(x)
Expand All @@ -54,14 +65,3 @@ def is_dask_collection(x):

def is_duck_dask_array(x):
return is_duck_array(x) and is_dask_collection(x)


dsk = DuckArrayModule("dask")
dask_version = dsk.version
dask_array_type = dsk.type

sp = DuckArrayModule("sparse")
sparse_array_type = sp.type
sparse_version = sp.version

cupy_array_type = DuckArrayModule("cupy").type