Feature Type
-
[ ] Adding new functionality to pandas
-
[X] Changing existing functionality in pandas
-
[ ] Removing existing functionality in pandas
Problem Description
Currently, most methods only make in-place alterations when explicitly told to (default is inplace = False
). pandas.DataFrame.insert
is an exception, working in true OOP-way. There is not even an inplace
argument for it.
I don't know if there is any justification for this choice, but I would expect this method to work as the others.
If this is desirable, I can work on this as well.
Feature Description
Add a new inplace
parameter for the pandas.DataFrame.insert
. Initally, its default will be inplace = True
, with a deprecation warning. In a future breaking change, it could be changed to inplace = False
df = df.insert(1, "A", col, inplace=False)
Alternative Solutions
I'm not aware of an alternative solution, pandas.DataFrame.insert
returns None
, like other methods with the inplace=True
parameter.
Additional Context
No response
Comment From: phofl
Hi, thanks for the issue.
I am -1 on this. What would be the advantage of making a copy here? There are other ways of emulating an insert if you want to do method chaining
Comment From: bhvieira
@phofl the advantage is consistency to the rest of the methods, imo
Comment From: jreback
-1 as well
and we r actively going to be deprecating inplace soon
Comment From: bhvieira
@jreback I see, but then insert
will continue to do inplace operations (while users often don't expect it)
Comment From: jreback
it's been the case since the very beginning of time (update as well)
Comment From: jbrockmendel
agreed on not adding inplace
, but id be +1 on adding copy
and returning a DataFrame object, xref #48141
Comment From: topper-123
-1 on this as well.
There seem to be relative agreement among the core devs in not going forward with this, so I'm closing this. Thanks for the proposal though @bhvieira.