Skip to content

check ExtensionType in is_datetime64_any_dtype for array-likes #57060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 2, 2024
3 changes: 1 addition & 2 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ Bug fixes
~~~~~~~~~
- Fixed bug in :meth:`DataFrame.join` inconsistently setting result index name (:issue:`55815`)
- Fixed bug in :meth:`Series.diff` allowing non-integer values for the ``periods`` argument. (:issue:`56607`)
-

Categorical
^^^^^^^^^^^
Expand Down Expand Up @@ -219,7 +218,7 @@ Sparse

ExtensionArray
^^^^^^^^^^^^^^
-
- Fixed bug in :meth:`api.types.is_datetime64_any_dtype` where a custom :class:`ExtensionDtype` would return ``False`` for array-likes (:issue:`57055`)
-

Styler
Expand Down
6 changes: 5 additions & 1 deletion pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,11 @@ def is_datetime64_any_dtype(arr_or_dtype) -> bool:
tipo = _get_dtype(arr_or_dtype)
except TypeError:
return False
return lib.is_np_dtype(tipo, "M") or isinstance(tipo, DatetimeTZDtype)
return (
lib.is_np_dtype(tipo, "M")
or isinstance(tipo, DatetimeTZDtype)
or (isinstance(tipo, ExtensionDtype) and tipo.kind == "M")
)


def is_datetime64_ns_dtype(arr_or_dtype) -> bool:
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from pandas.api.extensions import no_default
from pandas.api.types import (
is_bool_dtype,
is_datetime64_any_dtype,
is_float_dtype,
is_integer_dtype,
is_numeric_dtype,
Expand Down Expand Up @@ -1531,6 +1532,14 @@ def test_is_unsigned_integer_dtype(data):
assert not is_unsigned_integer_dtype(data)


def test_is_datetime64_any_dtype(data):
pa_type = data.dtype.pyarrow_dtype
if pa.types.is_timestamp(pa_type) or pa.types.is_date(pa_type):
assert is_datetime64_any_dtype(data)
else:
assert not is_datetime64_any_dtype(data)


def test_is_float_dtype(data):
pa_type = data.dtype.pyarrow_dtype
if pa.types.is_floating(pa_type):
Expand Down