8000 CoW: Set copy=False in internal usages of Series/DataFrame constructors by phofl · Pull Request #51834 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

CoW: Set copy=False in internal usages of Series/DataFrame constructors #51834

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
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Restrict usage of copy
  • Loading branch information
phofl committed Mar 13, 2023
commit 72e1d2de61c88491620bf5f0b0cd88befda6afc5
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3606,7 +3606,7 @@ def transpose(self, *args, copy: bool = False) -> DataFrame:

else:
new_arr = self.values.T
if copy:
if copy and not using_copy_on_write():
new_arr = new_arr.copy()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can pass copy=False below (which I think is correct, since in this code path we know that we have multiple blocks, and so self.values will always be a copy), then this copy if copy=True should also not be necessary?

I would also add a short comment mentioning why we can specify copy=False

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought so as well, couldn't figure out why we would do an additional copy here, but wasn't sure if I am missing something.

Added a comment

result = self._constructor(
new_arr,
Expand Down
0