Skip to content

BUG/API: PeriodIndex.unique returns ndarray #7540

Closed
@sinhrks

Description

@sinhrks

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignCompatpandas objects compatability with Numpy or Python functionsPeriodPeriod data type

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions