Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Level parameter of DataFrame.groupby should allow Sequences #836

Closed
jens-diewald opened this issue Dec 21, 2023 · 1 comment · Fixed by #837
Closed

Level parameter of DataFrame.groupby should allow Sequences #836

jens-diewald opened this issue Dec 21, 2023 · 1 comment · Fixed by #837

Comments

@jens-diewald
Copy link
Contributor

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.

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Dec 21, 2023

Yes, a PR is welcome, along with tests. Would need to change the type of level in groupby() in frame.pyi and series.pyi for all the overloads.

A test like you have above should suffice, i.e., you don't need to check all the overloads, although it would be good to have a test for both Series and DataFrame.

jens-diewald added a commit to jens-diewald/pandas-stubs that referenced this issue Dec 22, 2023
jens-diewald added a commit to jens-diewald/pandas-stubs that referenced this issue Dec 22, 2023
Dr-Irv pushed a commit that referenced this issue Dec 23, 2023
* Add test cases for level sequences

This test fail currently, as the level parameter
currently does not accept any sequences.

* Allow sequences for groupby level parameter

This fixes #836

* Add assert_type

* Remove unnecessary quotes
twoertwein pushed a commit to twoertwein/pandas-stubs that referenced this issue Dec 24, 2023
* Add test cases for level sequences

This test fail currently, as the level parameter
currently does not accept any sequences.

* Allow sequences for groupby level parameter

This fixes pandas-dev#836

* Add assert_type

* Remove unnecessary quotes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants