Skip to content

Commit

Permalink
Backport PR #49162 on branch 1.5.x (PERF: Fix performance regression …
Browse files Browse the repository at this point in the history
…for isin with mismatching dtypes) (#49165)

Backport PR #49162: PERF: Fix performance regression for isin with mismatching dtypes

Co-authored-by: Patrick Hoefler <61934744+phofl@users.noreply.github.com>
  • Loading branch information
meeseeksmachine and phofl committed Oct 18, 2022
1 parent 8429c50 commit 7286385
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.5.1.rst
Expand Up @@ -86,6 +86,7 @@ Fixed regressions
- Fixed Regression in :meth:`DataFrameGroupBy.apply` when user defined function is called on an empty dataframe (:issue:`47985`)
- Fixed regression in :meth:`DataFrame.apply` when passing non-zero ``axis`` via keyword argument (:issue:`48656`)
- Fixed regression in :meth:`Series.groupby` and :meth:`DataFrame.groupby` when the grouper is a nullable data type (e.g. :class:`Int64`) or a PyArrow-backed string array, contains null values, and ``dropna=False`` (:issue:`48794`)
- Fixed performance regression in :meth:`Series.isin` with mismatching dtypes (:issue:`49162`)
- Fixed regression in :meth:`DataFrame.to_parquet` raising when file name was specified as ``bytes`` (:issue:`48944`)
- Fixed regression in :class:`ExcelWriter` where the ``book`` attribute could no longer be set; however setting this attribute is now deprecated and this ability will be removed in a future version of pandas (:issue:`48780`)
- Fixed regression in :meth:`DataFrame.corrwith` when computing correlation on tied data with ``method="spearman"`` (:issue:`48826`)
Expand Down
10 changes: 6 additions & 4 deletions pandas/core/algorithms.py
Expand Up @@ -462,12 +462,14 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> npt.NDArray[np.bool_]:
)

if not isinstance(values, (ABCIndex, ABCSeries, ABCExtensionArray, np.ndarray)):
if not is_signed_integer_dtype(comps):
orig_values = values
values = _ensure_arraylike(list(values))

if 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(list(values))
else:
values = _ensure_arraylike(list(values))
values = construct_1d_object_array_from_listlike(list(orig_values))

elif isinstance(values, ABCMultiIndex):
# Avoid raising in extract_array
values = np.array(values)
Expand Down

0 comments on commit 7286385

Please sign in to comment.