Skip to content

Commit c14e08d

Browse files
committed
Combined redundant if-statements to improve readability and performance
1 parent cb16826 commit c14e08d

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

pandas/core/algorithms.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -541,24 +541,19 @@ def isin(comps: ListLike, values: ListLike) -> npt.NDArray[np.bool_]:
541541
elif isinstance(values.dtype, ExtensionDtype):
542542
return isin(np.asarray(comps_array), np.asarray(values))
543543

544-
# GH60678
545-
# Ensure values don't contain <NA>, otherwise it throws exception with np.in1d
546-
547-
values_contains_NA = False
548-
549-
if comps_array.dtype != object and len(values) <= 26:
550-
values_contains_NA = any(v is NA for v in values)
551-
552544
# GH16012
553545
# Ensure np.isin doesn't get object types or it *may* throw an exception
554546
# Albeit hashmap has O(1) look-up (vs. O(logn) in sorted array),
555547
# isin is faster for small sizes
556548

549+
# GH60678
550+
# Ensure values don't contain <NA>, otherwise it throws exception with np.in1d
551+
557552
if (
558553
len(comps_array) > _MINIMUM_COMP_ARR_LEN
559554
and len(values) <= 26
560555
and comps_array.dtype != object
561-
and not values_contains_NA
556+
and not any(v is NA for v in values)
562557
):
563558
# If the values include nan we need to check for nan explicitly
564559
# since np.nan it not equal to np.nan

0 commit comments

Comments
 (0)