Skip to content

Commit

Permalink
Fix upcasting with python builtin numbers and numpy 2
Browse files Browse the repository at this point in the history
  • Loading branch information
djhoese committed Apr 15, 2024
1 parent 2b2de81 commit f3c2c93
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions xarray/core/duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,15 @@ def as_shared_dtype(scalars_or_arrays, xp=np):

arrays = [asarray(x, xp=cp) for x in scalars_or_arrays]
else:
arrays = [asarray(x, xp=xp) for x in scalars_or_arrays]
#arrays = [asarray(x, xp=xp) for x in scalars_or_arrays]
arrays = [x if isinstance(x, (int, float, complex)) else asarray(x, xp=xp) for x in scalars_or_arrays]
# Pass arrays directly instead of dtypes to result_type so scalars
# get handled properly.
# Note that result_type() safely gets the dtype from dask arrays without
# evaluating them.
out_type = dtypes.result_type(*arrays)
return [astype(x, out_type, copy=False) for x in arrays]
#return [astype(x, out_type, copy=False) for x in arrays]
return [astype(x, out_type, copy=False) if hasattr(x, "dtype") else x for x in arrays]


def broadcast_to(array, shape):
Expand Down

0 comments on commit f3c2c93

Please sign in to comment.