|
13 | 13 | ABCIndexClass, ABCCategorical)
|
14 | 14 | from pandas.core.dtypes.common import (
|
15 | 15 | is_unsigned_integer_dtype, is_signed_integer_dtype,
|
16 |
| - is_integer_dtype, is_complex_dtype, |
| 16 | + is_integer_dtype, is_complex_dtype, is_integer, is_float, |
17 | 17 | is_object_dtype,
|
18 | 18 | is_categorical_dtype, is_sparse,
|
19 | 19 | is_period_dtype,
|
20 | 20 | is_numeric_dtype, is_float_dtype,
|
21 | 21 | is_bool_dtype, needs_i8_conversion,
|
22 | 22 | is_categorical, is_datetimetz, is_datetime_or_timedelta_dtype,
|
23 |
| - is_datetime64_any_dtype, is_datetime64tz_dtype, |
| 23 | + is_datetime64_any_dtype, is_datetime64tz_dtype, is_datetimelike, |
24 | 24 | is_timedelta64_dtype, is_interval_dtype,
|
25 | 25 | is_scalar, is_list_like,
|
26 | 26 | _ensure_platform_int, _ensure_object,
|
@@ -404,16 +404,18 @@ def isin(comps, values):
|
404 | 404 | if not isinstance(values, (ABCIndex, ABCSeries, np.ndarray)):
|
405 | 405 | values = construct_1d_object_array_from_listlike(list(values))
|
406 | 406 |
|
407 |
| - from pandas.core.dtypes.common import is_datetimelike, is_float |
408 | 407 | comps, dtype, _ = _ensure_data(comps)
|
409 |
| - # Convert `values` to `dtype` if `values` is datetime/float-like and `dtype` is datetime/float-like |
410 |
| - if (is_datetime_or_timedelta_dtype(dtype) and |
411 |
| - (is_datetime_or_timedelta_dtype(values) or |
412 |
| - all(is_datetimelike(i) for i in values))): |
413 |
| - values, _, _ = _ensure_data(values, dtype=dtype) |
414 |
| - elif (is_float_dtype(dtype) and |
415 |
| - (is_float_dtype(values) or |
416 |
| - all(is_float(i) for i in values))): |
| 408 | + # Convert `values` to `dtype` if dtype of `values` is like `dtype` |
| 409 | + check_int = (is_integer_dtype(dtype) and |
| 410 | + (is_integer_dtype(values) or |
| 411 | + all(is_integer(i) for i in values))) |
| 412 | + check_float = (is_float_dtype(dtype) and |
| 413 | + (is_float_dtype(values) or |
| 414 | + all(is_float(i) for i in values))) |
| 415 | + check_datetime = (is_datetime_or_timedelta_dtype(dtype) and |
| 416 | + (is_datetime_or_timedelta_dtype(values) or |
| 417 | + all(is_datetimelike(i) for i in values))) |
| 418 | + if check_int or check_float or check_datetime: |
417 | 419 | values, _, _ = _ensure_data(values, dtype=dtype)
|
418 | 420 | else:
|
419 | 421 | values, _, _ = _ensure_data(values)
|
|
0 commit comments