Skip to content
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/v2.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ Timedelta
Timezones
^^^^^^^^^
- Bug in :func:`infer_freq` that raises ``TypeError`` for ``Series`` of timezone-aware timestamps (:issue:`52456`)
- Bug in :meth:`DatetimeTZDtype.base` that always returns a NumPy dtype with nanosecond resolution (:issue:`52705`)
-

Numeric
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ class DatetimeTZDtype(PandasExtensionDtype):
type: type[Timestamp] = Timestamp
kind: str_type = "M"
num = 101
base = np.dtype("M8[ns]") # TODO: depend on reso?
_metadata = ("unit", "tz")
_match = re.compile(r"(datetime64|M8)\[(?P<unit>.+), (?P<tz>.+)\]")
_cache_dtypes: dict[str_type, PandasExtensionDtype] = {}
Expand All @@ -685,6 +684,10 @@ class DatetimeTZDtype(PandasExtensionDtype):
def na_value(self) -> NaTType:
return NaT

@cache_readonly
def base(self) -> DtypeObj: # type: ignore[override]
return np.dtype(f"M8[{self.unit}]")

# error: Signature of "str" incompatible with supertype "PandasExtensionDtype"
@cache_readonly
def str(self) -> str: # type: ignore[override]
Expand Down
1 change: 1 addition & 0 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def test_construction_non_nanosecond(self):
assert res._creso == NpyDatetimeUnit.NPY_FR_ms.value
assert res.str == "|M8[ms]"
assert str(res) == "datetime64[ms, US/Eastern]"
assert res.base == np.dtype("M8[ms]")

def test_day_not_supported(self):
msg = "DatetimeTZDtype only supports s, ms, us, ns units"
Expand Down