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

ENH: Add inplace argument to pandas.DataFrame.insert #50303

Closed
1 of 3 tasks
bhvieira opened this issue Dec 16, 2022 · 7 comments
Closed
1 of 3 tasks

ENH: Add inplace argument to pandas.DataFrame.insert #50303

bhvieira opened this issue Dec 16, 2022 · 7 comments
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@bhvieira
Copy link

Feature Type

  • Adding new functionality to pandas

  • 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

@bhvieira bhvieira added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 16, 2022
@phofl
Copy link
Member

phofl commented Dec 16, 2022

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

@bhvieira
Copy link
Author

@phofl the advantage is consistency to the rest of the methods, imo

@jreback
Copy link
Contributor

jreback commented Dec 16, 2022

-1 as well

and we r actively going to be deprecating inplace soon

@bhvieira
Copy link
Author

@jreback I see, but then insert will continue to do inplace operations (while users often don't expect it)

@jreback
Copy link
Contributor

jreback commented Dec 16, 2022

it's been the case since the very beginning of time (update as well)

@jbrockmendel
Copy link
Member

agreed on not adding inplace, but id be +1 on adding copy and returning a DataFrame object, xref #48141

@topper-123
Copy link
Contributor

-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.

@topper-123 topper-123 closed this as not planned Won't fix, can't repro, duplicate, stale May 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

5 participants