Closed
Description
import pandas as pd
dti = pd.date_range("2016-01-01", periods=3)
pi = dti.to_period("D")
dti.astype(pi.dtype) # <- OK
pi.astype(dti.dtype) # <- works but deprecated in #44398
pd.Series(dti).astype(pi.dtype) # <- OK
pd.Series(pi).astype(dti.dtype) # <- raises
In #44398 we deprecated PeriodIndex.astype(dt64). The motivation was that PeriodIndex.astype should be consistent with Series[Period].astype. I chose to deprecate the PeriodIndex behavior instead of allow it in Series.astype bc there's an optional keyword in PeriodIndex.astype that we're deprecating anyway.
I'm having seconds thoughts based on the fact that we do support Series[dt64].astype(period)
, and it seems like these should be able to round-trip.