-
-
Notifications
You must be signed in to change notification settings - Fork 18k
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
BUG: inplace behavior is inconsist for fillna #47188
Comments
This change is related to 03dd698 . As #46800 (comment) mentioned: I assumed |
Looks like at the end of Block.fillna adding a |
@jbrockmendel Thanks for quick feedback! IIUC, do you mean only # should make a copy
pdf["a"] = pdf["a"] + 10 But for method like # operate inplace
df.fillna({"x": -1, "y": -2, "z": -5}, inplace=True)
df.update(new_df)
df.eval("A = B + C", inplace=True) |
based on the title of this issue, i'm labelling as a regression and milestoning 1.4.x since both operations in the OP were consistent in pandas-1.3.5. of course, if the change for the second case is intentional and the first case is a bug that was not fixed by #43406, then could also choose not to backport any fix. if the second is considered the bug, then any fix should definitely be backported to restore the 1.3.5 behavior |
@simonjayhawkins Thanks for reply! It seems the Besides the code of fillnan in PR, below is the test code for import pandas as pd
import numpy as np
# Example for update
pdf = pd.DataFrame({"A": ["1", "2", "3", "4"], "B": ["100", "200", np.nan, np.nan]}, columns=["A", "B"])
new_pdf = pd.DataFrame({"B": ["x", np.nan, "y", np.nan], "C": ["100", "200", "300", "400"]},columns=["B", "C"])
pser = pdf.B
pdf.update(new_pdf)
# pser != pdf.B after 1.4
# 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 |
@simonjayhawkins @jbrockmendel Would this issue be fixed in 1.4.3? What should we really expect the behavior to be? According to history comments and discussion, I assume #47188 (comment) , |
I think updating inplace is sensible here? This is a subtle change so I think we should backport, because the fact that we are using setitem under the hood should not leak into the interface. If we want to change this, we should deprecate, but only makes sens if we don't get Copy on Write in for 2.0 |
@phofl Thanks for explanation, I updated the PR description, looks like the PR only fix the |
fix for update included in #47327 |
opened #47449 for |
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
Issue Description
Looks like behavior is a little bit differet in current pandas.
Expected Behavior
Always make a copy and doesn't write to existing array forDo in-place operation in all functions with inplace (such likeeval
/update
/fillna
).Installed Versions
1.4+
The text was updated successfully, but these errors were encountered: