Skip to content

BUG: inplace behavior changes after 1.4.x #46800

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
3 tasks done
Yikun opened this issue Apr 19, 2022 · 3 comments
Closed
3 tasks done

BUG: inplace behavior changes after 1.4.x #46800

Yikun opened this issue Apr 19, 2022 · 3 comments
Labels
Copy / view semantics Indexing Related to indexing on series/frames, not to indexes themselves Usage Question

Comments

@Yikun
Copy link
Contributor

Yikun commented Apr 19, 2022

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

pdf = pd.DataFrame({"A": range(1, 3), "B": range(4, 6), "C": range(7, 9)})
pser = pdf.A
pdf.eval("A = B + C", inplace=True)

Issue Description

Before 1.4.0:

>>> pdf.A
0    11
1    13
Name: A, dtype: int64
>>> pser
0    11
1    13
Name: A, dtype: int64

After 1.4.0:

>>> pdf.A
0    11
1    13
Name: A, dtype: int64
>>> pser   # <== behavior changed here
0    1
1    2
Name: A, dtype: int64

Expected Behavior

>>> pdf.A
0    11
1    13
Name: A, dtype: int64
>>> pser
0    11
1    13
Name: A, dtype: int64

Installed Versions

1.4.x+

@Yikun Yikun added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 19, 2022
@Yikun Yikun changed the title BUG: BUG: eval with inplace behavior changes after 1.4.x Apr 19, 2022
@Yikun Yikun changed the title BUG: eval with inplace behavior changes after 1.4.x BUG: df.eval with inplace behavior changes after 1.4.x Apr 19, 2022
@Yikun Yikun changed the title BUG: df.eval with inplace behavior changes after 1.4.x BUG: inplace behavior changes after 1.4.x Apr 21, 2022
@Yikun
Copy link
Contributor Author

Yikun commented Apr 21, 2022

pdf = pd.DataFrame({"A": range(1, 3), "B": range(4, 6), "C": range(7, 9)})
pser = pdf.A
pdf["A"] = pdf["A"] + 10
pser
pdf.A

Here is a simple test

@Yikun
Copy link
Contributor Author

Yikun commented Apr 21, 2022

first change commit: 03dd698

cc @jbrockmendel

@phofl
Copy link
Member

phofl commented Apr 22, 2022

Hi, thanks for your report.

This was wrong before 1.4.0 and works as expected now. This was also announced in the release notes. Setitem should always make a copy and never write into the existing array.

@phofl phofl closed this as completed Apr 22, 2022
@phofl phofl added Indexing Related to indexing on series/frames, not to indexes themselves Usage Question Copy / view semantics and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Copy / view semantics Indexing Related to indexing on series/frames, not to indexes themselves Usage Question
Projects
None yet
Development

No branches or pull requests

2 participants