Skip to content

Commit 6299599

Browse files
mtsokolmeeseeksmachine
authored andcommitted
Backport PR pandas-dev#54694: MAINT: Remove np.in1d function calls
1 parent 1dbd792 commit 6299599

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

pandas/core/algorithms.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -518,9 +518,9 @@ def isin(comps: ListLike, values: ListLike) -> npt.NDArray[np.bool_]:
518518
return isin(np.asarray(comps_array), np.asarray(values))
519519

520520
# GH16012
521-
# Ensure np.in1d doesn't get object types or it *may* throw an exception
521+
# Ensure np.isin doesn't get object types or it *may* throw an exception
522522
# Albeit hashmap has O(1) look-up (vs. O(logn) in sorted array),
523-
# in1d is faster for small sizes
523+
# isin is faster for small sizes
524524
if (
525525
len(comps_array) > _MINIMUM_COMP_ARR_LEN
526526
and len(values) <= 26
@@ -531,10 +531,10 @@ def isin(comps: ListLike, values: ListLike) -> npt.NDArray[np.bool_]:
531531
if isna(values).any():
532532

533533
def f(c, v):
534-
return np.logical_or(np.in1d(c, v), np.isnan(c))
534+
return np.logical_or(np.isin(c, v).ravel(), np.isnan(c))
535535

536536
else:
537-
f = np.in1d
537+
f = lambda a, b: np.isin(a, b).ravel()
538538

539539
else:
540540
common = np_find_common_type(values.dtype, comps_array.dtype)

pandas/core/arrays/interval.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1844,14 +1844,14 @@ def isin(self, values) -> npt.NDArray[np.bool_]:
18441844
# complex128 ndarray is much more performant.
18451845
left = self._combined.view("complex128")
18461846
right = values._combined.view("complex128")
1847-
# error: Argument 1 to "in1d" has incompatible type
1847+
# error: Argument 1 to "isin" has incompatible type
18481848
# "Union[ExtensionArray, ndarray[Any, Any],
18491849
# ndarray[Any, dtype[Any]]]"; expected
18501850
# "Union[_SupportsArray[dtype[Any]],
18511851
# _NestedSequence[_SupportsArray[dtype[Any]]], bool,
18521852
# int, float, complex, str, bytes, _NestedSequence[
18531853
# Union[bool, int, float, complex, str, bytes]]]"
1854-
return np.in1d(left, right) # type: ignore[arg-type]
1854+
return np.isin(left, right).ravel() # type: ignore[arg-type]
18551855

18561856
elif needs_i8_conversion(self.left.dtype) ^ needs_i8_conversion(
18571857
values.left.dtype

pandas/tseries/holiday.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,11 @@ def dates(
283283
holiday_dates = self._apply_rule(dates)
284284
if self.days_of_week is not None:
285285
holiday_dates = holiday_dates[
286-
np.in1d(
286+
np.isin(
287287
# error: "DatetimeIndex" has no attribute "dayofweek"
288288
holiday_dates.dayofweek, # type: ignore[attr-defined]
289289
self.days_of_week,
290-
)
290+
).ravel()
291291
]
292292

293293
if self.start_date is not None:

0 commit comments

Comments
 (0)