Skip to content

Commit a94e852

Browse files
phoflmroeschke
andauthored
PERF: Fix performance regression in isin for empty values (pandas-dev#49839)
Co-authored-by: Matthew Roeschke <[email protected]>
1 parent beab917 commit a94e852

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
@@ -1438,6 +1438,8 @@ def infer_dtype(value: object, skipna: bool = True) -> str:
14381438
else:
14391439
if not isinstance(value, list):
14401440
value = list(value)
1441+
if not value:
1442+
return "empty"
14411443

14421444
from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike
14431445
values = construct_1d_object_array_from_listlike(value)

pandas/core/algorithms.py

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

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

0 commit comments

Comments
 (0)