diff --git a/pandas/core/arrays/period.py b/pandas/core/arrays/period.py index adc09afab485b..e42e8b7195c2e 100644 --- a/pandas/core/arrays/period.py +++ b/pandas/core/arrays/period.py @@ -824,8 +824,10 @@ def to_timestamp(self, freq=None, how: str = "start") -> DatetimeArray: new_parr = self.asfreq(freq, how=how) + dt64_dtype = np.dtype("datetime64[ns]") + new_data = libperiod.periodarr_to_dt64arr(new_parr.asi8, base) - dta = DatetimeArray._from_sequence(new_data, dtype=np.dtype("M8[ns]")) + dta = DatetimeArray._from_sequence(new_data, dtype=dt64_dtype) if self.freq.name == "B": # See if we can retain BDay instead of Day in cases where diff --git a/pandas/tests/indexes/period/test_period.py b/pandas/tests/indexes/period/test_period.py index d465225da7f24..be9475aabc0b7 100644 --- a/pandas/tests/indexes/period/test_period.py +++ b/pandas/tests/indexes/period/test_period.py @@ -231,3 +231,29 @@ def test_dunder_array(array): np.array(obj, dtype=dtype) with pytest.raises(TypeError, match=msg): np.array(obj, dtype=getattr(np, dtype)) + + +def test_to_timestamp_monthly_resolution(): + idx = PeriodIndex(["2011-01", "NaT", "2011-02"], freq="2M") + ts = idx.to_timestamp() + assert ts.dtype == np.dtype("datetime64[ns]") + + +def test_to_timestamp_yearly_resolution(): + idx = PeriodIndex(["2011", "2012"], freq="Y") + ts = idx.to_timestamp() + assert ts.dtype == np.dtype("datetime64[ns]") + + +def test_to_timestamp_daily_resolution(): + idx = PeriodIndex(["2011-01-01", "2011-01-02"], freq="D") + ts = idx.to_timestamp() + assert ts.dtype == np.dtype("datetime64[ns]") + + +def test_to_timestamp_nanosecond_resolution(): + idx = PeriodIndex( + ["2011-01-01 00:00:00.000000001", "2011-01-01 00:00:00.000000002"], freq="ns" + ) + ts = idx.to_timestamp() + assert ts.dtype == np.dtype("datetime64[ns]")