BUG/API: PeriodIndex.unique returns ndarray (original) (raw)
Currently, Index.unique returns ndarray but DatetimeIndex.unique returns DatetimeIndex to preserve datetime information. I think PeriodIndex.unique should also return PeriodIndex (currently it returns ndarray).
I'd like to ask which is better to fix all Index.unique to return Index for consistency, or only fix PeriodIndex.
didx = pd.DatetimeIndex([datetime.datetime(2014, 1, 1), datetime.datetime(2014, 2, 1)])
didx.unique()
# <class 'pandas.tseries.index.DatetimeIndex'>
# [2014-01-01, 2014-02-01]
pidx = pd.PeriodIndex(['2014-01', '2014-02'], freq='M')
pidx.unique()
# [528 529]
type(pidx.unique())
# <type 'numpy.ndarray'>