-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: Clarify in pandas.DataFrame.drop that a copy is returned when inplace = False. #34955
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
Merged
simonjayhawkins
merged 3 commits into
pandas-dev:master
from
marinomaria:modify-df.drop-docstring
Jun 23, 2020
Merged
Changes from all commits
Commits
Show all changes
3 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 hidden or 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.
we should actually audit all of the inplace doc-strings and make them consistent (maybe even have a rule)
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 thought of this too but couldn’t figure out how to do it properly. I’m assuming there’s a better way besides searching for every method that takes an ‘inplace’ argument, checking if there’s any room for confusion and then make the adjustments.
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.
Hi, I am the author of #33451. Thank you for adressing this issue. In the issue I mention pandas.DataFrame.drop as an example but the scope is much broader.
In general, I might not know whether a pandas method returns a copy or a view, also if there is no 'inplace' argument.
According to https://stackoverflow.com/questions/23296282/what-rules-does-pandas-use-to-generate-a-view-vs-a-copy it appears that methods return a copy in general (assuming there is no 'inplace' argument and there is no indexing like https://pandas.pydata.org/docs/user_guide/indexing.html#returning-a-view-versus-a-copy).
However, I am confused why some methods (e.g., https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.assign.html), which do not have an 'inplace' argument, explicitly mentioned that a copy/new object is returned.
On the other hand, other methods do not mention anything at all or a VERY vague. E.g., according to the documentation (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.query.html), pd.DataFrame.query returns a 'DataFrame resulting from the provided query expression'.
Thus, when I use a method which I haven't used before or recently, I often have to investigate whether a copy is returned. And this is very cumbersome.
I wonder whether you can confirm that methods in general return a copy? If this is the case, and if I am correct that this is not mentioned in the user guide (?), I think this should definitely be highlighted in the user guide. In this case, it might also not be necessary to clarify whether a method returns a copy or a view (if there is no 'inplace' argument). 'Only' the documentation has to be tidied, i.e., parts that mention that a copy or view is returned (e.g., https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.assign.html) should be removed.
However, if it is not true that methods return a copy in general, I would highly appreciate if every method clarifies whether it returns a copy or a view.