Skip to content

API: DataFrame.eval, inplace option #9297

Closed
@shoyer

Description

@shoyer

Building off of #9229, it's generally much better to create new dataframes rather than to modify existing ones. It's both more chainable and less prone to the bugs/errors associated with mutable state.

So it seems to me that a saner API design would be to make assignment operations with eval/query return a new frame rather than modify the existing one, i.e., df.eval('x = y ** 2') should be equivalent to df.assign(x = lambda df: df.y ** 2) (as currently defined in #9239).

In my experience, something like df.query('x = 0') is more likely intended to be equivalent to df.query('x == 0') rather than df['x'] = 0, which has the unfortunate effect of also modifying the original data. In fact, I have made this exact mistake before -- and apparently others have as well (see #8664).

Thoughts? The query/eval syntax is marked as experimental, so I think we have the freedom to change this.

CC @TomAugspurger @cpcloud @jreback

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions