-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: inplace parameter will not perform the operation in place on multi column-sliced DataFrame #34359
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
Comments
Please let us know all the version details as mentioned in the Github Bug documentation. |
@dgun-y Currently, selecting multiple columns of a dataframe returns a copy, and not a view (and hence, the inplace is working on a copy, and not filling the original dataframe) The basic reason is that selecting multiple columns with a list is "fancy" or "advanced" indexing in numpy's terms, which makes a copy (on the other hand, "slicing" gives a view). Now, pandas has some additional complexity due to the BlockManager layout (https://uwekorn.com/2020/05/24/the-one-pandas-internal.html), which makes that even those numpy rules don't always apply for pandas. |
I suspected as much, thank you for the response.
By this, should I assume for the worst in the future, that even slices of single columns may exhibit similar behavior? |
No, slicing a single column will always be a view, AFAIK |
Got it, thanks! |
Environment: Python 3.7.7 / NumPy 1.18.4 / Pandas 1.0.3
I have been testing the
inplace=True
parameters for a couple of functions, includingDataFrame.fillna()
andDataFrame.clip()
.When I use the inplace parameter on a multi-column slicing of a DataFrame, it will not alter the original DataFrame.
For instance, using the simple DataFrame below,
the code
will produce
as opposed to
Strangely enough, the parameter works perfectly when I'm slicing out just a single column
or when I'm using the position-based slicing method
.iloc
without specifying the first columnLet me know if this is the accepted/expected behavior or if there is a workaround.
Thanks!
The text was updated successfully, but these errors were encountered: