Skip to content

BUG: is_datetime64tz_dtype shortcut only for DatetimeTZDtype #48640

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 1 commit into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Conversion
^^^^^^^^^^
- Bug in constructing :class:`Series` with ``int64`` dtype from a string list raising instead of casting (:issue:`44923`)
- Bug in :meth:`DataFrame.eval` incorrectly raising an ``AttributeError`` when there are negative values in function call (:issue:`46471`)
- Bug where any :class:`ExtensionDtype` subclass with ``kind="M"`` would be interpreted as a timezone type (:issue:`34986`)
-

Strings
Expand Down
5 changes: 3 additions & 2 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,10 @@ def is_datetime64tz_dtype(arr_or_dtype) -> bool:
>>> is_datetime64tz_dtype(s)
True
"""
if isinstance(arr_or_dtype, ExtensionDtype):
if isinstance(arr_or_dtype, DatetimeTZDtype):
# GH#33400 fastpath for dtype object
return arr_or_dtype.kind == "M"
# GH 34986
return True

if arr_or_dtype is None:
return False
Expand Down
13 changes: 13 additions & 0 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
CategoricalDtype,
CategoricalDtypeType,
DatetimeTZDtype,
ExtensionDtype,
IntervalDtype,
PeriodDtype,
)
Expand Down Expand Up @@ -239,6 +240,18 @@ def test_is_datetime64tz_dtype():
assert com.is_datetime64tz_dtype(pd.DatetimeIndex(["2000"], tz="US/Eastern"))


def test_custom_ea_kind_M_not_datetime64tz():
# GH 34986
class NotTZDtype(ExtensionDtype):
@property
def kind(self) -> str:
return "M"

not_tz_dtype = NotTZDtype()
assert not com.is_datetime64tz_dtype(not_tz_dtype)
assert not com.needs_i8_conversion(not_tz_dtype)


def test_is_timedelta64_dtype():
assert not com.is_timedelta64_dtype(object)
assert not com.is_timedelta64_dtype(None)
Expand Down