From 210d0fe454d0e36376b41a3d2e9b248445f48c73 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Sun, 14 Nov 2021 09:14:37 -0500 Subject: [PATCH] DOC: Remove use of as_type for PeriodIndex to DatetimeIndex conversion --- doc/source/user_guide/timeseries.rst | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/source/user_guide/timeseries.rst b/doc/source/user_guide/timeseries.rst index a112c632ceb25..3ddb6434ed932 100644 --- a/doc/source/user_guide/timeseries.rst +++ b/doc/source/user_guide/timeseries.rst @@ -2073,14 +2073,18 @@ The ``period`` dtype can be used in ``.astype(...)``. It allows one to change th # change monthly freq to daily freq pi.astype("period[D]") - # convert to DatetimeIndex - pi.astype("datetime64[ns]") - # convert to PeriodIndex dti = pd.date_range("2011-01-01", freq="M", periods=3) dti dti.astype("period[M]") +.. deprecated:: 1.4.0 + Converting PeriodIndex to DatetimeIndex with ``.astype(...)`` is deprecated and will raise in a future version. Use ``obj.to_timestamp(how).tz_localize(dtype.tz)`` instead. + +.. ipython:: python + + # convert to DatetimeIndex + pi.to_timestamp(how="start") PeriodIndex partial string indexing ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~