Skip to content

Index.unique() should always return an Index object of the same type #13395

Closed
@shoyer

Description

@shoyer

This should also be noted in the docstring for the method.

Currently, it sometimes returns numpy arrays:

>>> pd.DatetimeIndex(['2000-01-01', '2000-01-02']).unique()
DatetimeIndex(['2000-01-01', '2000-01-02'], dtype='datetime64[ns]', freq=None)

>>> pd.Index([0, 1, 2]).unique()
array([0, 1, 2])

Most of the work here is probably writing comprehensive tests to check each index type.

xref: https://github.com/pydata/pandas/pull/13361/files/17209f92330c5e949934aec9dea039b35faf6e40#r66179418

Metadata

Metadata

Assignees

No one assigned

    Labels

    Compatpandas objects compatability with Numpy or Python functionsIndexingRelated to indexing on series/frames, not to indexes themselves

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions