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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v2.2.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Fixed regressions

Bug fixes
~~~~~~~~~
-
- Bug in :meth:`api.types.is_datetime64_any_dtype` where a custom :class:`ExtensionDtype` would not return ``True`` for array-likes (:issue:`57055`)

.. ---------------------------------------------------------------------------
.. _whatsnew_221.other:
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