Skip to content

Commit f3c2c93

Browse files
committed
Fix upcasting with python builtin numbers and numpy 2
1 parent 2b2de81 commit f3c2c93

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

xarray/core/duck_array_ops.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,15 @@ def as_shared_dtype(scalars_or_arrays, xp=np):
229229

230230
arrays = [asarray(x, xp=cp) for x in scalars_or_arrays]
231231
else:
232-
arrays = [asarray(x, xp=xp) for x in scalars_or_arrays]
232+
#arrays = [asarray(x, xp=xp) for x in scalars_or_arrays]
233+
arrays = [x if isinstance(x, (int, float, complex)) else asarray(x, xp=xp) for x in scalars_or_arrays]
233234
# Pass arrays directly instead of dtypes to result_type so scalars
234235
# get handled properly.
235236
# Note that result_type() safely gets the dtype from dask arrays without
236237
# evaluating them.
237238
out_type = dtypes.result_type(*arrays)
238-
return [astype(x, out_type, copy=False) for x in arrays]
239+
#return [astype(x, out_type, copy=False) for x in arrays]
240+
return [astype(x, out_type, copy=False) if hasattr(x, "dtype") else x for x in arrays]
239241

240242

241243
def broadcast_to(array, shape):

0 commit comments

Comments
 (0)