diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index 894e1d95a17bc..7889829516f7f 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -22,7 +22,6 @@ is_list_like, is_period_dtype, is_scalar, - needs_i8_conversion, ) from pandas.core.dtypes.concat import concat_compat from pandas.core.dtypes.generic import ABCIndex, ABCIndexClass, ABCSeries @@ -484,7 +483,7 @@ def where(self, cond, other=None): if is_categorical_dtype(other): # e.g. we have a Categorical holding self.dtype - if needs_i8_conversion(other.categories): + if is_dtype_equal(other.categories.dtype, self.dtype): other = other._internal_get_values() if not is_dtype_equal(self.dtype, other.dtype): diff --git a/pandas/core/internals/blocks.py b/pandas/core/internals/blocks.py index 024d3b205df77..87892a804dac3 100644 --- a/pandas/core/internals/blocks.py +++ b/pandas/core/internals/blocks.py @@ -2284,11 +2284,7 @@ def to_native_types( return np.atleast_2d(result) def should_store(self, value) -> bool: - return ( - issubclass(value.dtype.type, np.datetime64) - and not is_datetime64tz_dtype(value) - and not is_extension_array_dtype(value) - ) + return is_datetime64_dtype(value.dtype) def set(self, locs, values): """ @@ -2536,9 +2532,7 @@ def fillna(self, value, **kwargs): return super().fillna(value, **kwargs) def should_store(self, value) -> bool: - return issubclass( - value.dtype.type, np.timedelta64 - ) and not is_extension_array_dtype(value) + return is_timedelta64_dtype(value.dtype) def to_native_types(self, slicer=None, na_rep=None, quoting=None, **kwargs): """ convert to our native types format, slicing if desired """