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
inplacedoesn'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=Truewill 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=Truedoesn'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
selfshould 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
DataFramenameddf, using the memory in the address 1000-2000, and you dodf.operation(inplace=True),dfwill 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
dfis 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.
Uh oh!
There was an error while loading. Please reload this page.
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
inplaceparameters? A quick grep shows around 60 methods with aninplaceparameter, 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.
Uh oh!
There was an error while loading. Please reload this page.
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
renameorfillnaoperation 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: