Skip to content

Commit e5f6245

Browse files
committed
unit tests pass
1 parent a482acd commit e5f6245

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

pandas/core/algorithms.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
is_period_dtype,
2020
is_numeric_dtype, is_float_dtype,
2121
is_bool_dtype, needs_i8_conversion,
22-
is_categorical, is_datetimetz,
22+
is_categorical, is_datetimetz, is_datetime_or_timedelta_dtype,
2323
is_datetime64_any_dtype, is_datetime64tz_dtype,
2424
is_timedelta64_dtype, is_interval_dtype,
2525
is_scalar, is_list_like,
@@ -70,9 +70,9 @@ def _ensure_data(values, dtype=None):
7070
# we are actually coercing to uint64
7171
# until our algos support uint8 directly (see TODO)
7272
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):
7474
return _ensure_int64(values), 'int64', 'int64'
75-
elif (is_unsigned_integer_dtype(values) and
75+
elif (is_unsigned_integer_dtype(values) or
7676
is_unsigned_integer_dtype(dtype)):
7777
return _ensure_uint64(values), 'uint64', 'uint64'
7878
elif is_float_dtype(values) or is_float_dtype(dtype):
@@ -405,7 +405,11 @@ def isin(comps, values):
405405
values = construct_1d_object_array_from_listlike(list(values))
406406

407407
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)
409413

410414
# faster for larger cases to use np.in1d
411415
f = lambda x, y: htable.ismember_object(x, values)
@@ -414,7 +418,7 @@ def isin(comps, values):
414418
# Ensure np.in1d doesn't get object types or it *may* throw an exception
415419
if len(comps) > 1000000 and not is_object_dtype(comps):
416420
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):
418422
try:
419423
values = values.astype('int64', copy=False)
420424
comps = comps.astype('int64', copy=False)
@@ -423,7 +427,7 @@ def isin(comps, values):
423427
values = values.astype(object)
424428
comps = comps.astype(object)
425429

426-
elif is_float_dtype(comps):
430+
elif is_float_dtype(comps) and is_float_dtype(values):
427431
try:
428432
values = values.astype('float64', copy=False)
429433
comps = comps.astype('float64', copy=False)
@@ -432,6 +436,9 @@ def isin(comps, values):
432436
except (TypeError, ValueError):
433437
values = values.astype(object)
434438
comps = comps.astype(object)
439+
else:
440+
values = values.astype(object)
441+
comps = comps.astype(object)
435442

436443
return f(comps, values)
437444

0 commit comments

Comments
 (0)