Skip to content

Commit 595226a

Browse files
committed
simplify
1 parent fe02c18 commit 595226a

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

icechunk-python/python/icechunk/xarray.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections.abc import Hashable, Mapping, MutableMapping
22
from dataclasses import dataclass, field
3+
from importlib.util import find_spec
34
from typing import Any, Literal, overload
45

56
import numpy as np
@@ -20,6 +21,11 @@
2021
ZarrWriteModes = Literal["w", "w-", "a", "a-", "r+", "r"]
2122

2223

24+
try:
25+
has_dask = find_spec("dask") is not None
26+
except ImportError:
27+
has_dask = False
28+
2329
if Version(xr.__version__) < Version("2024.10.0"):
2430
raise ValueError(
2531
f"Writing to icechunk requires Xarray>=2024.10.0 but you have {xr.__version__}. Please upgrade."
@@ -35,11 +41,11 @@
3541

3642

3743
def is_dask_collection(x: Any) -> bool:
38-
try:
44+
if has_dask:
3945
from dask.base import is_dask_collection
4046

4147
return is_dask_collection(x)
42-
except ImportError:
48+
else:
4349
return False
4450

4551

0 commit comments

Comments
 (0)