19
19
is_period_dtype ,
20
20
is_numeric_dtype , is_float_dtype ,
21
21
is_bool_dtype , needs_i8_conversion ,
22
- is_categorical , is_datetimetz ,
22
+ is_categorical , is_datetimetz , is_datetime_or_timedelta_dtype ,
23
23
is_datetime64_any_dtype , is_datetime64tz_dtype ,
24
24
is_timedelta64_dtype , is_interval_dtype ,
25
25
is_scalar , is_list_like ,
@@ -70,9 +70,9 @@ def _ensure_data(values, dtype=None):
70
70
# we are actually coercing to uint64
71
71
# until our algos support uint8 directly (see TODO)
72
72
return np .asarray (values ).astype ('uint64' ), 'bool' , 'uint64'
73
- elif is_signed_integer_dtype (values ) and is_signed_integer_dtype (dtype ):
73
+ elif is_signed_integer_dtype (values ) or is_signed_integer_dtype (dtype ):
74
74
return _ensure_int64 (values ), 'int64' , 'int64'
75
- elif (is_unsigned_integer_dtype (values ) and
75
+ elif (is_unsigned_integer_dtype (values ) or
76
76
is_unsigned_integer_dtype (dtype )):
77
77
return _ensure_uint64 (values ), 'uint64' , 'uint64'
78
78
elif is_float_dtype (values ) or is_float_dtype (dtype ):
@@ -405,7 +405,11 @@ def isin(comps, values):
405
405
values = construct_1d_object_array_from_listlike (list (values ))
406
406
407
407
comps , dtype , _ = _ensure_data (comps )
408
- values , _ , _ = _ensure_data (values , dtype = dtype )
408
+ if (all (is_datetime_or_timedelta_dtype (i ) for i in values ) and
409
+ is_datetime_or_timedelta_dtype (dtype )):
410
+ values , _ , _ = _ensure_data (values , dtype = dtype )
411
+ else :
412
+ values , _ , _ = _ensure_data (values )
409
413
410
414
# faster for larger cases to use np.in1d
411
415
f = lambda x , y : htable .ismember_object (x , values )
@@ -414,7 +418,7 @@ def isin(comps, values):
414
418
# Ensure np.in1d doesn't get object types or it *may* throw an exception
415
419
if len (comps ) > 1000000 and not is_object_dtype (comps ):
416
420
f = lambda x , y : np .in1d (x , y )
417
- elif is_integer_dtype (comps ):
421
+ elif is_integer_dtype (comps ) and is_integer_dtype ( values ) :
418
422
try :
419
423
values = values .astype ('int64' , copy = False )
420
424
comps = comps .astype ('int64' , copy = False )
@@ -423,7 +427,7 @@ def isin(comps, values):
423
427
values = values .astype (object )
424
428
comps = comps .astype (object )
425
429
426
- elif is_float_dtype (comps ):
430
+ elif is_float_dtype (comps ) and is_float_dtype ( values ) :
427
431
try :
428
432
values = values .astype ('float64' , copy = False )
429
433
comps = comps .astype ('float64' , copy = False )
@@ -432,6 +436,9 @@ def isin(comps, values):
432
436
except (TypeError , ValueError ):
433
437
values = values .astype (object )
434
438
comps = comps .astype (object )
439
+ else :
440
+ values = values .astype (object )
441
+ comps = comps .astype (object )
435
442
436
443
return f (comps , values )
437
444
0 commit comments