diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index f9117253b61c1..d6d33ed873564 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -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 ^^^^^^^^^^^ @@ -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 diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 5e5b7bdad74d8..a53bbe9935684 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -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: diff --git a/pandas/tests/extension/test_arrow.py b/pandas/tests/extension/test_arrow.py index 6970c589dd36f..62e4629ca7cb7 100644 --- a/pandas/tests/extension/test_arrow.py +++ b/pandas/tests/extension/test_arrow.py @@ -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, @@ -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):