Skip to content

inplace dropna? #1960

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
jseabold opened this issue Sep 24, 2012 · 6 comments · Fixed by #5247
Closed

inplace dropna? #1960

jseabold opened this issue Sep 24, 2012 · 6 comments · Fixed by #5247
Labels
API Design Enhancement Internals Related to non-user accessible pandas implementation Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@jseabold
Copy link
Contributor

see related discussion in #2325

Possible and/or desirable to add an inplace keyword to dropna? Maybe an out keyword, so you can avoid typing the assignment? [Edit: I guess out doesn't really make sense like it does for numpy ufuncs.] Don't really mind if there's a copy even I just get tired of always doing assignment to the same name when I'm doing pre-, post-processing, etc.

dataframe = dataframe.action()
@wesm
Copy link
Member

wesm commented Sep 24, 2012

What do you think about having methods like idropna for shorter in-place modification?

@changhiskhan
Copy link
Contributor

doesn't the i- prefix usually indicate positional indexing? like irow, icol, and get_value vs iget_value

@wesm
Copy link
Member

wesm commented Sep 24, 2012

I was thinking re: __iadd__ which is the inplace add magic method

@jseabold
Copy link
Contributor Author

Well, now I'd associate it with iadd, but my first reaction was with indexing as well. I don't really know what to do here. It doesn't kill me to type inplace=True. I'm in the habit now and that's how I noticed dropna didn't have it. If you wanted to be cute (I don't necessarily)

dataframe.ip.dropna()
dataframe.ip.rename(...)

@jtratner
Copy link
Contributor

Now that we have a different representation for NDFrame, couldn't this be as simple as doing something along the lines of:

  1. Do dropna or drop.
  2. Set index and _data to that of the created object.
  3. Delete the other object.
  4. delete/clear all of the caches on the original object (both _cache for cache_readonly and the other cacher things.

Don't return self if inplace.

That way references to the original NDFrame wrapper refer to the new object. Easy to do with Series too now that it doesn't inherit NDFrame.

@jtratner
Copy link
Contributor

and then call finalize to copy over any other metadata.

We could rely on __finalize__ to handle tseries/other attributes intelligently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Enhancement Internals Related to non-user accessible pandas implementation Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants