File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change 1515 cftime = None
1616
1717
18+ def _is_duck_dask_array (x ):
19+ """Return True if the input is a dask array."""
20+ # Code copied and simplified from xarray < 2024.02 (xr.core.pycompat.is_duck_dask_array)
21+ try :
22+ from dask .base import is_dask_collection
23+ except ImportError :
24+ return False
25+
26+ return (
27+ is_dask_collection (x )
28+ and hasattr (x , "ndim" )
29+ and hasattr (x , "shape" )
30+ and hasattr (x , "dtype" )
31+ and (
32+ (hasattr (x , "__array_function__" ) and hasattr (x , "__array_ufunc__" ))
33+ or hasattr (x , "__array_namespace__" )
34+ )
35+ )
36+
37+
1838def _contains_cftime_datetimes (array ) -> bool :
1939 """Check if an array contains cftime.datetime objects"""
2040 # Copied / adapted from xarray.core.common
21- from xarray .core .pycompat import is_duck_dask_array
22-
2341 if cftime is None :
2442 return False
2543 else :
2644 if array .dtype == np .dtype ("O" ) and array .size > 0 :
2745 sample = array .ravel ()[0 ]
28- if is_duck_dask_array (sample ):
46+ if _is_duck_dask_array (sample ):
2947 sample = sample .compute ()
3048 if isinstance (sample , np .ndarray ):
3149 sample = sample .item ()
Original file line number Diff line number Diff line change 33What's New
44----------
55
6+ v0.8.10 (unreleased)
7+ ====================
8+ - Fix methods in ``utils `` to work with xarray >= 2024.02.0. By `Pascal Bourgault `_.
9+
610v0.8.9 (Feb 06, 2023)
711=====================
812- Convert integer (e.g. ``1 ``) units to string (e.g. ``"1" ``) for pint. By `Justus Magin `_.
You can’t perform that action at this time.
0 commit comments