API/ENH: allow Period to be a first-class type via a PeriodBlockinternal type · Issue #7964 · pandas-dev/pandas (original) (raw)

@jreback

Instead of having a represenation of an array of Period objects (object dtype) in a Series/DataFrame. Allow an internal type of PeriodBlock to represent, similary to DatetimeBlock.

Here is a usecase. The following would be very simple if to_period(...) returned a PeriodIndex

In [59]: df = DataFrame({'date' : pd.date_range('20130101 00:01:00',periods=5,freq='61s')})

In [60]: df
Out[60]: 
                 date
0 2013-01-01 00:01:00
1 2013-01-01 00:02:01
2 2013-01-01 00:03:02
3 2013-01-01 00:04:03
4 2013-01-01 00:05:04

In [61]: df.date.dt.to_period('T')                   
Out[61]: 
0    2013-01-01 00:01
1    2013-01-01 00:02
2    2013-01-01 00:03
3    2013-01-01 00:04
4    2013-01-01 00:05
dtype: object

In [62]: pd.Series(pd.PeriodIndex(df.date.dt.to_period('T')+1).to_timestamp())
Out[62]: 
0   2013-01-01 00:02:00
1   2013-01-01 00:03:00
2   2013-01-01 00:04:00
3   2013-01-01 00:05:00
4   2013-01-01 00:06:00
dtype: datetime64[ns]