Skip to content

BUG/API: PeriodIndex.unique returns ndarray #7540

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sinhrks opened this issue Jun 21, 2014 · 1 comment · Fixed by #7843
Closed

BUG/API: PeriodIndex.unique returns ndarray #7540

sinhrks opened this issue Jun 21, 2014 · 1 comment · Fixed by #7843
Labels
API Design Compat pandas objects compatability with Numpy or Python functions Period Period data type
Milestone

Comments

@sinhrks
Copy link
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'>
@jreback
Copy link
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Compat pandas objects compatability with Numpy or Python functions Period Period data type
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants