Skip to content

groupby breaks when using duplicated level names #21075

Closed
@guenteru

Description

@guenteru

Hi,
I updated to version 0.23.0 and all of a sudden the following code breaks:

import pandas as pd
df = pd.DataFrame(data={'date': list(pd.date_range('5.1.2018', '5.10.2018')),
                        'vals': list(range(10))})
df.groupby([df.date.dt.month, df.date.dt.day])['vals'].sum()

ValueError: Duplicated level name: "date", assigned to level 1, is already used for level 0.

Expected output:

Using version 0.22.0 the same code yields the following:

date  date
5     1       0
      2       1
      3       2
      4       3
      5       4
      6       5
      7       6
      8       7
      9       8
      10      9
Name: vals, dtype: int64

It obviously contains duplicated level names. I get why this might be a problem, but as of version 0.23.0 it's not possible to specify the resulting level names.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GroupbyMultiIndexRegressionFunctionality that used to work in a prior pandas version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions