Closed
Description
Related to #7485.
Currently, DatetimeIndex.asobject
raises ValueError
when it contains NaT
, otherwise PeriodIndex
doesn't inconsistently.
I think these should work the same way, and would like to confirm PeriodIndex
should raise ValueError
, or DatetimeIndex.asobject
allows NaT
. There may be historical reason, but I'm not sure why DatetimeIndex
raises ValueError
even though we can create object-dtype Index
containning NaT
didx = pd.DatetimeIndex([datetime.datetime(2014, 1, 1), pd.NaT])
didx.asobject
# ValueError: DatetimeIndex with NaT cannot be converted to object
pidx = pd.PeriodIndex(['2014-01', 'NaT'], freq='M')
pidx.asobject
# Index([2014-01, NaT], dtype='object')