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