Skip to content

Commit 782037d

Browse files
authored
BUG: is_datetime64tz_dtype shortcut only for DatetimeTZDtype (#48640)
1 parent 5550fd9 commit 782037d

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

doc/source/whatsnew/v1.6.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ Conversion
150150
^^^^^^^^^^
151151
- Bug in constructing :class:`Series` with ``int64`` dtype from a string list raising instead of casting (:issue:`44923`)
152152
- Bug in :meth:`DataFrame.eval` incorrectly raising an ``AttributeError`` when there are negative values in function call (:issue:`46471`)
153+
- Bug where any :class:`ExtensionDtype` subclass with ``kind="M"`` would be interpreted as a timezone type (:issue:`34986`)
153154
-
154155

155156
Strings

pandas/core/dtypes/common.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,10 @@ def is_datetime64tz_dtype(arr_or_dtype) -> bool:
382382
>>> is_datetime64tz_dtype(s)
383383
True
384384
"""
385-
if isinstance(arr_or_dtype, ExtensionDtype):
385+
if isinstance(arr_or_dtype, DatetimeTZDtype):
386386
# GH#33400 fastpath for dtype object
387-
return arr_or_dtype.kind == "M"
387+
# GH 34986
388+
return True
388389

389390
if arr_or_dtype is None:
390391
return False

pandas/tests/dtypes/test_common.py

+13
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
CategoricalDtype,
1414
CategoricalDtypeType,
1515
DatetimeTZDtype,
16+
ExtensionDtype,
1617
IntervalDtype,
1718
PeriodDtype,
1819
)
@@ -239,6 +240,18 @@ def test_is_datetime64tz_dtype():
239240
assert com.is_datetime64tz_dtype(pd.DatetimeIndex(["2000"], tz="US/Eastern"))
240241

241242

243+
def test_custom_ea_kind_M_not_datetime64tz():
244+
# GH 34986
245+
class NotTZDtype(ExtensionDtype):
246+
@property
247+
def kind(self) -> str:
248+
return "M"
249+
250+
not_tz_dtype = NotTZDtype()
251+
assert not com.is_datetime64tz_dtype(not_tz_dtype)
252+
assert not com.needs_i8_conversion(not_tz_dtype)
253+
254+
242255
def test_is_timedelta64_dtype():
243256
assert not com.is_timedelta64_dtype(object)
244257
assert not com.is_timedelta64_dtype(None)

0 commit comments

Comments
 (0)