Skip to content

Commit

Permalink
Revert "Try updating result_type for array API"
Browse files Browse the repository at this point in the history
This reverts commit 3f7670b.
  • Loading branch information
dcherian committed Apr 18, 2024
1 parent 6115dd8 commit e3493b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
16 changes: 7 additions & 9 deletions xarray/core/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ def is_datetime_like(dtype):

def result_type(
*arrays_and_dtypes: np.typing.ArrayLike | np.typing.DTypeLike,
xp=np,
) -> np.dtype:
"""Like np.result_type, but with type promotion rules matching pandas.
Expand All @@ -185,13 +184,12 @@ def result_type(
-------
numpy.dtype for the result.
"""
types = {xp.result_type(t) for t in arrays_and_dtypes}
types = {np.result_type(t).type for t in arrays_and_dtypes}

if xp == np:
for left, right in PROMOTE_TO_OBJECT:
if any(issubclass(t.type, left) for t in types) and any(
issubclass(t.type, right) for t in types
):
return np.dtype(object)
for left, right in PROMOTE_TO_OBJECT:
if any(issubclass(t, left) for t in types) and any(
issubclass(t, right) for t in types
):
return np.dtype(object)

return xp.result_type(*arrays_and_dtypes)
return np.result_type(*arrays_and_dtypes)
2 changes: 1 addition & 1 deletion xarray/core/duck_array_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def as_shared_dtype(scalars_or_arrays, xp=np):
# get handled properly.
# Note that result_type() safely gets the dtype from dask arrays without
# evaluating them.
out_type = dtypes.result_type(*arrays, xp=xp)
out_type = dtypes.result_type(*arrays)
return [
astype(x, out_type, copy=False) if hasattr(x, "dtype") else x for x in arrays
]
Expand Down

0 comments on commit e3493b0

Please sign in to comment.