Skip to content

API: ban mutation within groupby.apply #12653

Closed
@jreback

Description

@jreback
Contributor

xref #8662
xref #12652

This makes pandas code jump thru hoops and is a complete anti-pattern for pandas. let's nuke it. users should never do this.

Activity

added this to the 0.19.0 milestone on Mar 17, 2016
modified the milestones: 0.20.0, Next Major Release on Mar 23, 2017
jbrockmendel

jbrockmendel commented on Dec 1, 2019

@jbrockmendel
Member

agreed this is a footgun. brainstorming how to implement:

  • document that it isnt supported and be done with it
  • maybe a contextmanager to make the relevant objects immutable within the relevant calls
rhshadrach

rhshadrach commented on Jun 24, 2020

@rhshadrach
Member

@jbrockmendel with the contextmanager, are you thinking doing a comparison after the apply call to see if the objects involved changed? Is there a way to avoid a copy here?

jbrockmendel

jbrockmendel commented on Jun 24, 2020

@jbrockmendel
Member

with the contextmanager, are you thinking doing a comparison after the apply call to see if the objects involved changed?

I am thinking of setting the array.flags.writeable to False for any ndarrays contained inside the DataFrame. We'd need to implement something analogous for ExtensionArrays.

12 remaining items

Loading
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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jreback@jbrockmendel@MarcoGorelli@rhshadrach

        Issue actions

          API: ban mutation within groupby.apply · Issue #12653 · pandas-dev/pandas