Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
PERF: Fix performance regression in isin for empty values
  • Loading branch information
phofl committed Nov 22, 2022
commit 17a3be8141b452d2fb28dbe3fcd9f5147c4052be
2 changes: 2 additions & 0 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,8 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
else:
if not isinstance(value, list):
value = list(value)
if not value:
return "empty"

from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
values = construct_1d_object_array_from_listlike(value)
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,11 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> npt.NDArray[np.bool_]:
orig_values = list(values)
values = _ensure_arraylike(orig_values)

if is_numeric_dtype(values) and not is_signed_integer_dtype(comps):
if (
len(values) > 0
and is_numeric_dtype(values)
and not is_signed_integer_dtype(comps)
):
# GH#46485 Use object to avoid upcast to float64 later
# TODO: Share with _find_common_type_compat
values = construct_1d_object_array_from_listlike(orig_values)
Expand Down