Skip to content

Sorting within groupby causes duplication of index level #11802

Closed
@tdhopper

Description

@tdhopper

When I run this code on 0.17.0 on Python 3.5.0

import pandas as pd
d = pd.DataFrame(data=[[2, 1]])
print(d.index)
print((d.
 groupby(level=0).
 apply(lambda d: 
       d.sort_values(0)
      )
 ).index)

I get

Int64Index([0], dtype='int64')
MultiIndex(levels=[[0], [0]],
           labels=[[0], [0]])

The index gets duplicated (and turned into a multiindex) as a result of the sort within the groupby.

Appears to be a bug to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapBugGroupby

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions