Skip to content

DEPR: disallow mutating operations in groupby.apply #31759

Closed
@jbrockmendel

Description

@jbrockmendel
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.

Activity

jreback

jreback commented on Feb 6, 2020

@jreback
Contributor

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

cc @TomAugspurger
cc @mrocklin

mrocklin

mrocklin commented on Feb 6, 2020

@mrocklin
Contributor

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

mroeschke commented on Jun 28, 2020

@mroeschke
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    ApplyApply, Aggregate, Transform, MapGroupby

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mrocklin@jreback@jbrockmendel@mroeschke

        Issue actions

          DEPR: disallow mutating operations in groupby.apply · Issue #31759 · pandas-dev/pandas