@@ -427,37 +427,40 @@ def isin(comps, values):
427
427
values , _ , _ = _ensure_data (values )
428
428
429
429
# faster for larger cases to use np.in1d
430
- f = lambda x , y : htable .ismember_object (x . astype ( object ) , y . astype ( object ) )
430
+ f = lambda x , y : htable .ismember_object (x , y )
431
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
- is_int = lambda x : ((x == np .int64 ) or (x == int ))
436
- is_float = lambda x : ((x == np .float64 ) or (x == float ))
437
-
438
- int_flg = False
439
- float_flg = False
440
-
441
435
if len (comps_types ) == len (values_types ) == 1 :
442
436
comps_types = comps_types .pop ()
443
437
values_types = values_types .pop ()
444
- int_flg = (is_int (comps_types ) and is_int (values_types ))
445
- float_flg = (is_float (comps_types ) and is_float (values_types ))
438
+
439
+ is_int = lambda x : ((x == np .int64 ) or (x == int ))
440
+ is_float = lambda x : ((x == np .float64 ) or (x == float ))
446
441
447
442
# GH16012
448
443
# Ensure np.in1d doesn't get object types or it *may* throw an exception
449
444
if len (comps ) > 1000000 and not is_object_dtype (comps ):
450
445
f = lambda x , y : np .in1d (x , y )
451
- elif int_flg :
452
- values = values .astype ('int64' , copy = False )
453
- comps = comps .astype ('int64' , copy = False )
454
- f = lambda x , y : htable .ismember_int64 (x , y )
455
-
456
- elif float_flg :
457
- values = values .astype ('float64' , copy = False )
458
- comps = comps .astype ('float64' , copy = False )
459
- checknull = isna (values ).any ()
460
- f = lambda x , y : htable .ismember_float64 (x , y , checknull )
446
+ elif (is_int (comps_types ) and is_int (values_types )):
447
+ try :
448
+ values = values .astype ('int64' , copy = False )
449
+ comps = comps .astype ('int64' , copy = False )
450
+ 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 :
457
+ values = values .astype ('float64' , copy = False )
458
+ comps = comps .astype ('float64' , copy = False )
459
+ checknull = isna (values ).any ()
460
+ f = lambda x , y : htable .ismember_float64 (x , y , checknull )
461
+ except (TypeError , ValueError ):
462
+ values = values .astype (object )
463
+ comps = comps .astype (object )
461
464
462
465
return f (comps , values )
463
466
0 commit comments