-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
DOC: Improve "inplace" param in Dataframe.rename() docs #24037
Closed
nmusolino
wants to merge
2
commits into
pandas-dev:master
from
nmusolino:rename_inplace_docstring_23076
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is technically correct. The name is misleading, but using
inplace
doesn't necessarily mean that we're modifying theDataFrame
, as we can be returning a copy.I think the previous description is more accurate, except that it sounds like
inplace=True
will return a newDataFrame
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't understand your first paragraph. Can you give an example of when an operation with
inplace=True
doesn't modify "self", i.e. the data frame on which the method is called?When inplace is True, the method should modify the data frame, and no second frame should be created. When inplace is False, the method should return a second data frame, and
self
should be unmodified.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have a
DataFrame
nameddf
, using the memory in the address 1000-2000, and you dodf.operation(inplace=True)
,df
will be modified, but the data can be now in the memory address 3000-4000.So, technically speaking, the operation is not in place, as the result has been copied to a different location (even if the reference
df
is reassigned to the new memory).That's why I don't like your description, as for a user who doesn't care about the memory is perfectly fine and correct. But if you think about the memory, you description is not really correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nmusolino there are about 2 inplace operations that actually operate inplace. all others, simply do an internal copy, do the op, then assign back to the top level data. inplace has never been a real operation in pandas, nor will it ever be. This is why we are deprecating it. You can certainly give a longer explanation, but discouraging usage would be good here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jreback are we ready to deprecate all
inplace
parameters? A quick grep shows around 60 methods with aninplace
parameter, so it's not so much work to start raising warnings (and update the descriptions) for all them.Or do we prefer to wait?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@datapythonista :
See #16529 - I think we were planning to wait until 1.0, though can always push up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing out the issue @gfyoung, I'll continue the conversation there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@datapythonista, @jreback , I understand that these operations may involve copies. I wrote earlier that "internal data structures (e.g. block manager or index) might be copied even when inplace is True."
I think the distinction you are trying to draw is that a
rename
orfillna
operation does not necessarily overwrite individual elements in place; is that right? As a simple example, I seem to recall that Index objects are generally immutable, so any operation that changes the index would necessarily replace the index.Avoiding that implication is a reasonable point. To be clear, however, the methods are modifying the dataframe.
How about this description?
Or a simpler, more generic version: