Skip to content

Level parameter of DataFrame.groupby should allow Sequences #836

Closed
@jens-diewald

Description

@jens-diewald

The level parameter of DataFrame.groupby does not except sequences, when it should. (Corresponding Doc)
This is the same as pandas-dev/pandas#47548

To Reproduce
From the linked Issue above

import pandas as pd
df = pd.DataFrame([[1, 2, 3, 4], [5, 6, 7, 8]], columns=['a', 'b', 'c', 'd']).set_index(['a', 'b', 'c'])

print(df.groupby(level=[0, 1]).sum())

My System

  • Windows 10
  • Python 3.11
  • MyPy 1.5.1
  • pandas-stubs 2.1.4.231218

Potential Fix
The issue linked above was fixed by changing the type of level from Level | None to IndexLabel | None. (pandas-dev/pandas#47560)
I suppose, the same Fix should be applied to the groupby-Overloads in pandas-stubs/core/frame.pyi.
I am happy to create a pull request, if that helps.
But i would appreciate it, if someone more involved with this library could confirm that the proposed fix makes sense.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions