Skip to content

Commit 7c6414d

Browse files
jmoralezpmhatre1
authored andcommitted
check ExtensionType in is_datetime64_any_dtype for array-likes (pandas-dev#57060)
* check for ExtensionType in is_datetime64_any_dtype * use pre-commit * add test and move doc entry * check not date in test * fix condition * check type is not datetime.date * fix comparison * move description to ExtensionArray * return True for date types
1 parent ad90316 commit 7c6414d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

pandas/core/dtypes/common.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,11 @@ def is_datetime64_any_dtype(arr_or_dtype) -> bool:
890890
tipo = _get_dtype(arr_or_dtype)
891891
except TypeError:
892892
return False
893-
return lib.is_np_dtype(tipo, "M") or isinstance(tipo, DatetimeTZDtype)
893+
return (
894+
lib.is_np_dtype(tipo, "M")
895+
or isinstance(tipo, DatetimeTZDtype)
896+
or (isinstance(tipo, ExtensionDtype) and tipo.kind == "M")
897+
)
894898

895899

896900
def is_datetime64_ns_dtype(arr_or_dtype) -> bool:

pandas/tests/extension/test_arrow.py

+9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from pandas.api.extensions import no_default
5454
from pandas.api.types import (
5555
is_bool_dtype,
56+
is_datetime64_any_dtype,
5657
is_float_dtype,
5758
is_integer_dtype,
5859
is_numeric_dtype,
@@ -1531,6 +1532,14 @@ def test_is_unsigned_integer_dtype(data):
15311532
assert not is_unsigned_integer_dtype(data)
15321533

15331534

1535+
def test_is_datetime64_any_dtype(data):
1536+
pa_type = data.dtype.pyarrow_dtype
1537+
if pa.types.is_timestamp(pa_type) or pa.types.is_date(pa_type):
1538+
assert is_datetime64_any_dtype(data)
1539+
else:
1540+
assert not is_datetime64_any_dtype(data)
1541+
1542+
15341543
def test_is_float_dtype(data):
15351544
pa_type = data.dtype.pyarrow_dtype
15361545
if pa.types.is_floating(pa_type):

0 commit comments

Comments
 (0)