Skip to content

Commit db014ba

Browse files
committed
Ignore casting if we get a TypeError (indicates sparse <= 0.10.0)
1 parent 01d1b37 commit db014ba

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

xarray/core/duck_array_ops.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,15 @@ def trapz(y, x, axis):
150150

151151

152152
def astype(data, **kwargs):
153-
return data.astype(**kwargs)
153+
try:
154+
return data.astype(**kwargs)
155+
except TypeError as e:
156+
# FIXME: This should no longer be necessary in future versions of sparse
157+
# Current versions of sparse (v0.10.0) don't support the "casting" kwarg
158+
# This was fixed by https://github.com/pydata/sparse/pull/392
159+
if "casting" in repr(e):
160+
kwargs.pop("casting")
161+
return data.astype(**kwargs)
154162

155163

156164
def asarray(data, xp=np):

0 commit comments

Comments
 (0)