Skip to content

Commit fb52fb6

Browse files
committed
better patch
1 parent c8f854c commit fb52fb6

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

pandas/core/algorithms.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -506,30 +506,6 @@ def isin(comps: ListLike, values: ListLike) -> npt.NDArray[np.bool_]:
506506
orig_values = list(values)
507507
values = _ensure_arraylike(orig_values, func_name="isin-targets")
508508

509-
try:
510-
src = comps.dtype # type: ignore[union-attr]
511-
tar = values.dtype
512-
# check only valid dtypes related to implicit conversion to float64
513-
# other data types derived from 64-bit integers such as U/Int64Dtype
514-
# should also work
515-
if (
516-
src.kind in "iu"
517-
and src.itemsize == 8 # type: ignore[union-attr]
518-
and tar.kind in "iu"
519-
and tar.itemsize == 8 # type: ignore[union-attr]
520-
):
521-
is_implicit_conversion_to_float64 = src != tar
522-
else:
523-
is_implicit_conversion_to_float64 = False
524-
except (TypeError, AttributeError, ImportError):
525-
# invalid comparison
526-
is_implicit_conversion_to_float64 = False
527-
528-
if is_implicit_conversion_to_float64:
529-
# GH#46485 Use object to avoid upcast to float64 later
530-
# TODO: Share with _find_common_type_compat
531-
values = construct_1d_object_array_from_listlike(orig_values)
532-
533509
elif isinstance(values, ABCMultiIndex):
534510
# Avoid raising in extract_array
535511
values = np.array(values)
@@ -581,6 +557,16 @@ def f(c, v):
581557

582558
else:
583559
common = np_find_common_type(values.dtype, comps_array.dtype)
560+
if (
561+
values.dtype.kind in "iu"
562+
and comps_array.dtype.kind in "iu"
563+
and common == np.float64
564+
):
565+
# GH#46485
566+
# Let's np_find_common_type do the job and return float64
567+
# when it cannot do otherwise with integers
568+
# We replace it by an object
569+
common = np.dtype("O")
584570
values = values.astype(common, copy=False)
585571
comps_array = comps_array.astype(common, copy=False)
586572
f = htable.ismember

0 commit comments

Comments
 (0)