Skip to content

API: Remove kwargs from GroupBy #29511

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

Merged
merged 3 commits into from
Nov 12, 2019

Conversation

topper-123
Copy link
Contributor

Remove kwargs from _GroupBy`.__init__ and adds an explicit mutated parameter name instead. Also makes related changes.

Avoiding kwargs when possible is better for typing ergonomics.

Optional, only accepts keyword argument 'mutated' and is passed
to groupby.
mutated : bool, False
`mutated` is passed to groupby.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what mutated actually does. It's tested for in window/test_grouper.py so assume it has something to do with windowing ops. anyone got a suggestion for a better doc string?

@jbrockmendel
Copy link
Member

generally +1. im also unclear on the mutated thing. I epxect we dont want users passing it directly, wondering if it can be kept out of the top-level method signature

@topper-123
Copy link
Contributor Author

wondering if it can be kept out of the top-level method signature.

It is already allowed in the top-level signature, it's just hidden, so it would have to go through a deprecation process. But else I agree.

@WillAyd
Copy link
Member

WillAyd commented Nov 9, 2019

I am actually -1 on this change; unfortunate that we accept kwargs here but mutated is entirely an internal construction. I don't think we should expose it out as part of the GroupBy API

@topper-123
Copy link
Contributor Author

If mutated is internal, I think it should not be in the NDFrame.groupby signature, becuase that is a public signature. It should just call pandas.core.groupby.groupby.groupby directly, bypassing NDFrame.groupby.

@@ -7829,7 +7829,7 @@ def groupby(
group_keys=True,
squeeze=False,
observed=False,
**kwargs
mutated=False,
Copy link
Contributor

Choose a reason for hiding this comment

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

this is changing a public API. The reason the kwargs was added was to work around some internal routines calling this. So I wouldn't do this; rather we can work on cleaning how this is called to avoid passing thru here.

@topper-123 topper-123 force-pushed the cln_grouper_kwargs branch 5 times, most recently from e926495 to a7f1ead Compare November 12, 2019 06:58
@topper-123
Copy link
Contributor Author

topper-123 commented Nov 12, 2019

I've made a few changes:

  • the mutated parameter in NDFrame.groupby has been formally deprecated.
  • I've renamed grouper.groupby.groupby to grouper.grouper.get_groupby to better signal it's a function
  • I've typed out the parameters of get_groupby to make its signature explicit.

It didn't seem that any internal functionality actually used mutated. At least no tests that don't explicitly use mutated failed.

@jreback
Copy link
Contributor

jreback commented Nov 12, 2019

why would you deprecate? it is not public

@jorisvandenbossche
Copy link
Member

It didn't seem that any internal functionality actually used mutated. At least no tests that don't explicitly use mutated failed.

If this is correct, we could also directly remove it? (it has never been publicly exposed, only hidden in the kwargs, so I don't think a user could ever have known to pass a mutated keyword?)

@topper-123
Copy link
Contributor Author

Ok, I've removed mutated from NDFrame.groupby.

@topper-123 topper-123 force-pushed the cln_grouper_kwargs branch 2 times, most recently from 5d6e070 to 2f0aa75 Compare November 12, 2019 08:15
@jreback jreback merged commit 17db6c5 into pandas-dev:master Nov 12, 2019
@jreback
Copy link
Contributor

jreback commented Nov 12, 2019

thanks @topper-123 nice clean

Reksbril pushed a commit to Reksbril/pandas that referenced this pull request Nov 18, 2019
@topper-123 topper-123 deleted the cln_grouper_kwargs branch December 1, 2019 21:44
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
proost pushed a commit to proost/pandas that referenced this pull request Dec 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants