@@ -453,30 +453,34 @@ def isin(comps: AnyArrayLike, values: AnyArrayLike) -> npt.NDArray[np.bool_]:
453
453
else :
454
454
values = extract_array (values , extract_numpy = True , extract_range = True )
455
455
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 ):
459
459
# i.e. Extension Array
460
- return comps .isin (values )
460
+ return comps_array .isin (values )
461
461
462
- elif needs_i8_conversion (comps .dtype ):
462
+ elif needs_i8_conversion (comps_array .dtype ):
463
463
# 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 )
468
468
# TODO: not quite right ... Sparse/Categorical
469
469
elif needs_i8_conversion (values .dtype ):
470
- return isin (comps , values .astype (object ))
470
+ return isin (comps_array , values .astype (object ))
471
471
472
472
elif isinstance (values .dtype , ExtensionDtype ):
473
- return isin (np .asarray (comps ), np .asarray (values ))
473
+ return isin (np .asarray (comps_array ), np .asarray (values ))
474
474
475
475
# GH16012
476
476
# Ensure np.in1d doesn't get object types or it *may* throw an exception
477
477
# Albeit hashmap has O(1) look-up (vs. O(logn) in sorted array),
478
478
# 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
+ ):
480
484
# If the values include nan we need to check for nan explicitly
481
485
# since np.nan it not equal to np.nan
482
486
if isna (values ).any ():
@@ -488,12 +492,12 @@ def f(c, v):
488
492
f = np .in1d
489
493
490
494
else :
491
- common = np .find_common_type ([values .dtype , comps .dtype ], [])
495
+ common = np .find_common_type ([values .dtype , comps_array .dtype ], [])
492
496
values = values .astype (common , copy = False )
493
- comps = comps .astype (common , copy = False )
497
+ comps_array = comps_array .astype (common , copy = False )
494
498
f = htable .ismember
495
499
496
- return f (comps , values )
500
+ return f (comps_array , values )
497
501
498
502
499
503
def factorize_array (
0 commit comments