Skip to content
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

REGR: DataFrame.eval not respecting inplace argument in pandas 1.4 #47449

Closed
simonjayhawkins opened this issue Jun 21, 2022 · 7 comments · Fixed by #47550
Closed

REGR: DataFrame.eval not respecting inplace argument in pandas 1.4 #47449

simonjayhawkins opened this issue Jun 21, 2022 · 7 comments · Fixed by #47550
Labels
Bug expressions pd.eval, query Regression Functionality that used to work in a prior pandas version
Milestone

Comments

@simonjayhawkins
Copy link
Member

import pandas as pd
import numpy as np

# Example for eval
pdf = pd.DataFrame({"A": range(1, 6), "B": range(10, 0, -2), "C": range(11, 16)})
pser = pdf.A
pdf.eval("A = B + C", inplace=True)
# pser != pdf.A after 1.4

Originally posted by @Yikun in #47188 (comment)

@simonjayhawkins simonjayhawkins added Regression Functionality that used to work in a prior pandas version expressions pd.eval, query labels Jun 21, 2022
@simonjayhawkins simonjayhawkins added this to the 1.4.3 milestone Jun 21, 2022
@Yikun
Copy link
Contributor

Yikun commented Jun 21, 2022

Thanks!

@simonjayhawkins
Copy link
Member Author

moving to 1.4.4

@CloseChoice
Copy link
Member

CloseChoice commented Jun 29, 2022

first bad commit: [ 03dd698 ] BUG: DataFrame.setitem sometimes operating inplace (#43406)

cc @jbrockmendel

@jbrockmendel
Copy link
Member

jbrockmendel commented Jul 11, 2022

I'm unclear on the problem. we want (pser == pdf.A).all(), right? Thats what I see on mainWoops, nope.

@jbrockmendel
Copy link
Member

In core.computation.eval L387 we do target[assigner] = ret. Changing that to

if inplace:
    target.loc[:, assigner] = ret
else:
    target[assigner] =ret

fixes the OP example. Haven't run the test suite with this, or even looked that closely at the code to see if it is reasonable.

@jorisvandenbossche
Copy link
Member

@Yikun we are fixing this in #47550, but in general I would recommend to not rely on this too much (updating Series by performing inplace on the DataFrame). There are plans to change that behaviour (#36195), and actually also to deprecate the inplace keyword (#16529)

@Yikun
Copy link
Contributor

Yikun commented Aug 12, 2022

@jorisvandenbossche Thanks for your info!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug expressions pd.eval, query Regression Functionality that used to work in a prior pandas version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants