-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
TYP: Update type results for Groupby.count() and Groupby.size() #45904
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me from a typing perspective.
This code sample raises |
I fixed it. Edited above. @simonjayhawkins @jbrockmendel just did a newer commit that takes advantage of the generic aspect of the |
running code sample through interpreter gives...
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Dr-Irv lgtm can you update the PR title to be more descriptive TYP: ...
For the record, here is what I used for testing: import pandas as pd
from typing import TYPE_CHECKING
if not TYPE_CHECKING:
def reveal_type(*args, **kwargs):
pass
ind = pd.MultiIndex.from_product([["a", "b"], ["x", "y"]], names=["ab", "xy"])
df = pd.DataFrame({"x": [1, 2, 3, 4], "y": [4, 5, 6, 7]})
s = pd.Series([1, 2, 3, 4], index=ind)
cnt_df = df.groupby("x").count()
print(type(cnt_df))
cnt_df_s = df.groupby("x").y.count()
print(type(cnt_df_s))
# siz_df = df.groupby("x").size()
# print(type(siz_df))
app_df = df.groupby("x").apply(sum)
print(type(app_df))
cnt_df_a = df.groupby("x", as_index=False).count()
print(type(cnt_df_a))
cnt_df_s_a = df.groupby("x", as_index=False).y.count()
print(type(cnt_df_s_a))
# siz_df_a = df.groupby("x", as_index=False).size()
# print(type(siz_df_a))
app_df_a = df.groupby("x", as_index=False).apply(sum)
print(type(app_df_a))
cnt_s = s.groupby("ab").count()
print(type(cnt_s))
# siz_s = s.groupby("xy").size()
# print(type(siz_s))
app_s = s.groupby("xy").apply(sum)
print(type(app_s))
reveal_type(cnt_df)
reveal_type(cnt_df_s)
# reveal_type(siz_df)
reveal_type(app_df)
reveal_type(cnt_df_a)
reveal_type(cnt_df_s_a)
# reveal_type(siz_df_a)
reveal_type(app_df_a)
reveal_type(cnt_s)
# reveal_type(siz_s)
reveal_type(app_s) I took out the
The two |
@Dr-Irv status here |
@jreback all green now - merged with latest main |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.N/A
Here's a test using
mypy
that reveals the issue.Before this PR, the result of
mypy
on thereveal_type
lines is:After this PR, the result is:
This will be needed as we work on the general typing issues.