BUG/API: PeriodIndex.unique returns ndarray #7540

Closed
sinhrks opened this Issue Jun 21, 2014 · 1 comment

Comments

Projects
None yet
2 participants
Member

sinhrks commented Jun 21, 2014

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'>
Contributor

jreback commented Jun 21, 2014

this is a historical / compat as well. In theory could fix all of them, but I think lots of things (tests) will break. I am not sure if anything real will actually break. Give a try and see (but I agree PeriodIndex.unique should return a PeriodIndex

jreback added this to the 0.15.0 milestone Jul 7, 2014

jreback closed this in #7843 Jul 26, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment