Skip to content

Commit e391f13

Browse files
authored
is_dask_collection: micro optimization (#6107)
1 parent 2694046 commit e391f13

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

xarray/core/pycompat.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,19 @@ def __init__(self, mod):
4343
self.available = duck_array_module is not None
4444

4545

46+
dsk = DuckArrayModule("dask")
47+
dask_version = dsk.version
48+
dask_array_type = dsk.type
49+
50+
sp = DuckArrayModule("sparse")
51+
sparse_array_type = sp.type
52+
sparse_version = sp.version
53+
54+
cupy_array_type = DuckArrayModule("cupy").type
55+
56+
4657
def is_dask_collection(x):
47-
if DuckArrayModule("dask").available:
58+
if dsk.available:
4859
from dask.base import is_dask_collection
4960

5061
return is_dask_collection(x)
@@ -54,14 +65,3 @@ def is_dask_collection(x):
5465

5566
def is_duck_dask_array(x):
5667
return is_duck_array(x) and is_dask_collection(x)
57-
58-
59-
dsk = DuckArrayModule("dask")
60-
dask_version = dsk.version
61-
dask_array_type = dsk.type
62-
63-
sp = DuckArrayModule("sparse")
64-
sparse_array_type = sp.type
65-
sparse_version = sp.version
66-
67-
cupy_array_type = DuckArrayModule("cupy").type

0 commit comments

Comments
 (0)