Skip to content

Conversation

@Dr-Irv
Copy link
Collaborator

@Dr-Irv Dr-Irv commented Jun 28, 2025

@Dr-Irv Dr-Irv requested a review from twoertwein June 28, 2025 20:46
@schorlton-bugseq
Copy link

Thank you!

Copy link
Member

@twoertwein twoertwein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small optional changes (happy to merge without them):

  • include_groups is not deprecated, only include_groups=True, I would be fine keeping the test and adding include_groups: Literal[False] in the signature
  • it might be nice to have a test where a kwargs/args is incompatible with the func
@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jun 30, 2025

Two small optional changes (happy to merge without them):

  • include_groups is not deprecated, only include_groups=True, I would be fine keeping the test and adding include_groups: Literal[False] in the signature

Yes, but there are 2 issues with that.

  1. The argument will become irrelevant since only a value of False is accepted. So we shouldn't encourage its use.
  2. If we use ParamSpec, we can't have a keyword argument between *args and **kwargs in the typing stubs. See Is `typing.Protocol` the only way to concatenate the keyword-only arguments in `ParamSpec`? python/typing#1905
  • it might be nice to have a test where a kwargs/args is incompatible with the func

Yes, although I'm not sure how to write one! I just wanted to handle the use case reported.

@twoertwein
Copy link
Member

twoertwein commented Jun 30, 2025

  1. The argument will become irrelevant since only a value of False is accepted. So we shouldn't encourage its use.
  2. If we use ParamSpec, we can't have a keyword argument between *args and **kwargs in the typing stubs. See Is typing.Protocol the only way to concatenate the keyword-only arguments in ParamSpec? python/typing#1905

Thank you for the explanations!

Yes, although I'm not sure how to write one! I just wanted to handle the use case reported.

Something like

df.groupby("group", group_keys=False)[["group", "value"]].apply( add_constant_to_mean, constant="5" # typing: ignore )

should hopefully be flagged as wrong.

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Jun 30, 2025

Something like

df.groupby("group", group_keys=False)[["group", "value"]].apply( add_constant_to_mean, constant="5" # typing: ignore )

should hopefully be flagged as wrong.

Thanks for the suggestion. I've incorporated into the last commit

@twoertwein twoertwein merged commit 824065c into pandas-dev:main Jun 30, 2025
13 checks passed
@twoertwein
Copy link
Member

Thanks @Dr-Irv !

@DeflateAwning
Copy link

This PR is the bane of my existence. Can you please add back the overload for include_groups: Literal[False]

@Dr-Irv
Copy link
Collaborator Author

Dr-Irv commented Sep 30, 2025

This PR is the bane of my existence. Can you please add back the overload for include_groups: Literal[False]

No, you should modify your code to avoid using include_groups

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants