-
-
Notifications
You must be signed in to change notification settings - Fork 141
groupby with MultiIndex not annotated correctly #703
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
Comments
Can you indicate which version of pandas-stubs you are using? |
I am using But as said, I am not sure the patch is correct - I am not exactly sure if/when label/by combinations are allowed in |
OK, thanks. Can you create a PR (with tests) with your change? I see now that the docs say that you can't use |
Sorry, I misread. Yes, I can. Probably tomorrow. |
This happens with a Series as well: grp = series.groupby(level=["l1", "l2"])
...
No overload variant of "groupby" of "Series" matches argument type "list[str]" [call-overload] due to this pandas-stubs/pandas-stubs/core/series.pyi Line 609 in 6bb1215
|
This seems to have been fixed (or I can't reproduce it anymore on the latest version). |
Yes, seems like #837 closed this. |
Consider a DF or Series with a MultiIndex M1, M2, M3.
When grouping as in
grp = df.groupby(level=["M1", "M3"])
You will get an error like
This is due to the annotation of groupby as
The type "Level" is an alias for "Hashable" and allows only one level. I think it should be
Hashable|Sequence[Hashable]
or, as pandas calls it,IndexLabel
(+ the| None
)I've identified a few places (see attachment). However, I am not sure the patch is correct/complete. It is interesting to see that
stack
is annotated withlevel: Level | list[Level] = ...
whileunstack
haslevel: Level = ...
while IMHO both should beIndexLabel
.Also, I am not sure the groupby annotations are completey correct because I think you cannot use
df.groupby(by=not_None, level=other_not_None)
at the same time, yet the annotations seems to allow it.Minimum example code:
pyright outputs:
0001-MultiIndex-in-groupby.patch.gz
(Warning: I haven't tested/verified the patch!)
The text was updated successfully, but these errors were encountered: