Skip to content

ENH: change Index unique to return an Index/MultiIndex (rather than ndarray) #4126

Closed
@jreback

Description

@jreback

Change unique to return an Index/MultiIndex as needed (rather than an ndarray)

In [81]: tuples = [(0, 100, 1000),(0, 100, 1001),(0, 100, 1002), (1, 101, 1001)]

In [82]: index_3levels=pd.MultiIndex.from_tuples(tuples,names=["l1","l2","l3"])

In [83]: index_3levels
Out[83]: 
MultiIndex
[(0, 100, 1000), (0, 100, 1001), (0, 100, 1002), (1, 101, 1001)]

In [84]: index_3levels.droplevel('l3')
Out[84]: 
MultiIndex
[(0, 100), (0, 100), (0, 100), (1, 101)]

This becomes more intuitive (or maybe add uniquify keyword to droplevel?

In [85]: MultiIndex.from_tuples(index_3levels.droplevel('l3').unique())
Out[85]: 
MultiIndex
[(0, 100), (1, 101)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Duplicate ReportDuplicate issue or pull requestEnhancementIdeasLong-Term Enhancement DiscussionsIndexingRelated to indexing on series/frames, not to indexes themselvesMultiIndex

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions