Skip to content

DEPR: disallow mutating operations in groupby.apply #31759

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

Closed
jbrockmendel opened this issue Feb 6, 2020 · 3 comments
Closed

DEPR: disallow mutating operations in groupby.apply #31759

jbrockmendel opened this issue Feb 6, 2020 · 3 comments
Labels
Apply Apply, Aggregate, Transform, Map Groupby

Comments

@jbrockmendel
Copy link
Member

A common issue [citation needed] comes up in groupby.apply when a user passes a function that modifies its argument in-place. This is because we call the function on the first group first to see if we can use a fastpath, and then again when we apply it to all groups.

We could add a kwarg to specify if a function may mutate its data, e.g. gb.apply(myfunc, may_mutate=True) in which case we could avoid re-calling the function (probably means no fast-path). With may_mutate=False we could use a context in which we set the data's flags to be immutable before calling anything on it.

@jbrockmendel jbrockmendel added Apply Apply, Aggregate, Transform, Map Groupby labels Feb 6, 2020
@jreback
Copy link
Contributor

jreback commented Feb 6, 2020

dask has the keyword pure for this purpose
we could adopt it

cc @TomAugspurger
cc @mrocklin

@mrocklin
Copy link
Contributor

mrocklin commented Feb 6, 2020

In hindsight the term pure was a bad choice for us. It means lots of things, not all of which you may intend to communicate here.

@mroeschke
Copy link
Member

Looks like this is a duplicate of #12653

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Apply Apply, Aggregate, Transform, Map Groupby
Projects
None yet
Development

No branches or pull requests

4 participants