Skip to content

Commit f06a97d

Browse files
Backport PR #49839 on branch 1.5.x (PERF: Fix performance regression in isin for empty values) (#49860)
Backport PR #49839: PERF: Fix performance regression in isin for empty values Co-authored-by: Patrick Hoefler <[email protected]>
1 parent 949636d commit f06a97d

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

doc/source/whatsnew/v1.5.3.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ including other versions of pandas.
1313

1414
Fixed regressions
1515
~~~~~~~~~~~~~~~~~
16-
-
16+
- Fixed performance regression in :meth:`Series.isin` when ``values`` is empty (:issue:`49839`)
1717
-
1818

1919
.. ---------------------------------------------------------------------------

pandas/_libs/lib.pyx

+2
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,8 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
14801480
else:
14811481
if not isinstance(value, list):
14821482
value = list(value)
1483+
if not value:
1484+
return "empty"
14831485

14841486
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
14851487
values = construct_1d_object_array_from_listlike(value)

pandas/core/algorithms.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,11 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> npt.NDArray[np.bool_]:
465465
orig_values = values
466466
values = _ensure_arraylike(list(values))
467467

468-
if is_numeric_dtype(values) and not is_signed_integer_dtype(comps):
468+
if (
469+
len(values) > 0
470+
and is_numeric_dtype(values)
471+
and not is_signed_integer_dtype(comps)
472+
):
469473
# GH#46485 Use object to avoid upcast to float64 later
470474
# TODO: Share with _find_common_type_compat
471475
values = construct_1d_object_array_from_listlike(list(orig_values))

0 commit comments

Comments
 (0)