Skip to content

Commit

Permalink
Handle numpy missing the array api function astype (#8315)
Browse files Browse the repository at this point in the history
  • Loading branch information
Illviljan authored Oct 16, 2023
1 parent dafd726 commit 4520ce9
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions xarray/core/duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ def cumulative_trapezoid(y, x, axis):
def astype(data, dtype, **kwargs):
if hasattr(data, "__array_namespace__"):
xp = get_array_namespace(data)
if xp == np:
# numpy currently doesn't have a astype:
return data.astype(dtype, **kwargs)
return xp.astype(data, dtype, **kwargs)
return data.astype(dtype, **kwargs)

Expand Down

0 comments on commit 4520ce9

Please sign in to comment.