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 15
15
cftime = None
16
16
17
17
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
+
18
38
def _contains_cftime_datetimes (array ) -> bool :
19
39
"""Check if an array contains cftime.datetime objects"""
20
40
# Copied / adapted from xarray.core.common
21
- from xarray .core .pycompat import is_duck_dask_array
22
-
23
41
if cftime is None :
24
42
return False
25
43
else :
26
44
if array .dtype == np .dtype ("O" ) and array .size > 0 :
27
45
sample = array .ravel ()[0 ]
28
- if is_duck_dask_array (sample ):
46
+ if _is_duck_dask_array (sample ):
29
47
sample = sample .compute ()
30
48
if isinstance (sample , np .ndarray ):
31
49
sample = sample .item ()
Original file line number Diff line number Diff line change 3
3
What's New
4
4
----------
5
5
6
+ v0.8.10 (unreleased)
7
+ ====================
8
+ - Fix methods in ``utils `` to work with xarray >= 2024.02.0. By `Pascal Bourgault `_.
9
+
6
10
v0.8.9 (Feb 06, 2023)
7
11
=====================
8
12
- 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