@@ -453,30 +453,34 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> npt.NDArray[np.bool_]:
453453 else :
454454 values = extract_array (values , extract_numpy = True , extract_range = True )
455455
456- comps = _ensure_arraylike (comps )
457- comps = extract_array (comps , extract_numpy = True )
458- if not isinstance (comps , np .ndarray ):
456+ comps_array = _ensure_arraylike (comps )
457+ comps_array = extract_array (comps_array , extract_numpy = True )
458+ if not isinstance (comps_array , np .ndarray ):
459459 # i.e. Extension Array
460- return comps .isin (values )
460+ return comps_array .isin (values )
461461
462- elif needs_i8_conversion (comps .dtype ):
462+ elif needs_i8_conversion (comps_array .dtype ):
463463 # Dispatch to DatetimeLikeArrayMixin.isin
464- return pd_array (comps ).isin (values )
465- elif needs_i8_conversion (values .dtype ) and not is_object_dtype (comps .dtype ):
466- # e.g. comps are integers and values are datetime64s
467- return np .zeros (comps .shape , dtype = bool )
464+ return pd_array (comps_array ).isin (values )
465+ elif needs_i8_conversion (values .dtype ) and not is_object_dtype (comps_array .dtype ):
466+ # e.g. comps_array are integers and values are datetime64s
467+ return np .zeros (comps_array .shape , dtype = bool )
468468 # TODO: not quite right ... Sparse/Categorical
469469 elif needs_i8_conversion (values .dtype ):
470- return isin (comps , values .astype (object ))
470+ return isin (comps_array , values .astype (object ))
471471
472472 elif isinstance (values .dtype , ExtensionDtype ):
473- return isin (np .asarray (comps ), np .asarray (values ))
473+ return isin (np .asarray (comps_array ), np .asarray (values ))
474474
475475 # GH16012
476476 # Ensure np.in1d doesn't get object types or it *may* throw an exception
477477 # Albeit hashmap has O(1) look-up (vs. O(logn) in sorted array),
478478 # in1d is faster for small sizes
479- if len (comps ) > 1_000_000 and len (values ) <= 26 and not is_object_dtype (comps ):
479+ if (
480+ len (comps_array ) > 1_000_000
481+ and len (values ) <= 26
482+ and not is_object_dtype (comps_array )
483+ ):
480484 # If the values include nan we need to check for nan explicitly
481485 # since np.nan it not equal to np.nan
482486 if isna (values ).any ():
@@ -488,12 +492,12 @@ def f(c, v):
488492 f = np .in1d
489493
490494 else :
491- common = np .find_common_type ([values .dtype , comps .dtype ], [])
495+ common = np .find_common_type ([values .dtype , comps_array .dtype ], [])
492496 values = values .astype (common , copy = False )
493- comps = comps .astype (common , copy = False )
497+ comps_array = comps_array .astype (common , copy = False )
494498 f = htable .ismember
495499
496- return f (comps , values )
500+ return f (comps_array , values )
497501
498502
499503def factorize_array (
0 commit comments