@@ -415,41 +415,50 @@ def isin(comps, values):
415
415
return comps ._values .isin (values )
416
416
417
417
comps = com ._values_from_object (comps )
418
- comps , dtype_comps , _ = _ensure_data (comps )
418
+
419
+ comps , dtype , _ = _ensure_data (comps )
419
420
420
421
is_time_like = lambda x : (is_datetime_or_timedelta_dtype (x )
421
422
or isinstance (x , Timestamp ))
423
+ if is_time_like (dtype ):
424
+ values , _ , _ = _ensure_data (values , dtype = dtype )
425
+ else :
426
+ values , _ , _ = _ensure_data (values )
422
427
423
- is_int = lambda x : ((x == np .int64 ) or (x == int ))
428
+ # faster for larger cases to use np.in1d
429
+ f = lambda x , y : htable .ismember_object (x .astype (object ), y .astype (object ))
430
+
431
+ # This block checks if comps and values
432
+ # are all int or all float
433
+ int_flg = False
434
+ float_flg = False
424
435
436
+ is_int = lambda x : ((x == np .int64 ) or (x == int ))
425
437
is_float = lambda x : ((x == np .float64 ) or (x == float ))
426
438
427
- f = lambda x , y : htable .ismember_object (x .astype (object ), y .astype (object ))
439
+ comps_types = set (type (v ) for v in comps )
440
+ values_types = set (type (v ) for v in values )
441
+
442
+ if len (comps_types ) == len (values_types ) == 1 :
443
+ if (is_int (comps_types ) and is_int (values_types )):
444
+ int_flg = True
445
+ elif (is_float (comps_types ) and is_float (values_types )):
446
+ float_flg = True
428
447
429
448
# GH16012
430
449
# Ensure np.in1d doesn't get object types or it *may* throw an exception
431
- # faster for larger cases to use np.in1d
432
450
if len (comps ) > 1000000 and not is_object_dtype (comps ):
433
451
f = lambda x , y : np .in1d (x , y )
434
-
435
- if is_time_like (dtype_comps ):
436
- values , _ , _ = _ensure_data (values , dtype = dtype_comps )
437
- else :
438
- values , dtype_values , _ = _ensure_data (values )
439
- comps_types = set (type (v ) for v in comps )
440
- values_types = set (type (v ) for v in values )
441
- if len (comps_types ) == len (values_types ) == 1 :
442
- comps_types = comps_types .pop ()
443
- values_types = values_types .pop ()
444
- if (is_int (comps_types ) and is_int (values_types )):
445
- values = values .astype ('int64' , copy = False )
446
- comps = comps .astype ('int64' , copy = False )
447
- f = lambda x , y : htable .ismember_int64 (x , y )
448
- elif (is_float (comps_types ) and is_float (values_types )):
449
- values = values .astype ('float64' , copy = False )
450
- comps = comps .astype ('float64' , copy = False )
451
- checknull = isna (values ).any ()
452
- f = lambda x , y : htable .ismember_float64 (x , y , checknull )
452
+ elif int_flg :
453
+ values = values .astype ('int64' , copy = False )
454
+ comps = comps .astype ('int64' , copy = False )
455
+ f = lambda x , y : htable .ismember_int64 (x , y )
456
+
457
+ elif float_flg :
458
+ values = values .astype ('float64' , copy = False )
459
+ comps = comps .astype ('float64' , copy = False )
460
+ checknull = isna (values ).any ()
461
+ f = lambda x , y : htable .ismember_float64 (x , y , checknull )
453
462
454
463
return f (comps , values )
455
464
0 commit comments