-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Add lazy copy for swapaxes no op #50573
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
Conversation
Not totally sure what to do in the other copy case. This can return views in some cases, but copy is performed on the underlying array |
pandas/core/generic.py
Outdated
if copy: | ||
return self.copy() | ||
return self | ||
if not copy and copy is not None and not _using_copy_on_write(): |
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 not copy and copy is not None and not _using_copy_on_write(): | |
if copy is False and not _using_copy_on_write(): |
What I think we ideally should do is in case that This can be done here using some internal APIs, but to do this properly, it might be easier to have this as a method on the Manager. |
I've used ndarray_to_mgr for now, that's basically what we need 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.
I still think it's a bit cleaner to move this logic into the internals (we will need to same logic in DataFrame.transpose() as well), but fine for me to keep it like this for now.
typ="block", | ||
) | ||
assert isinstance(new_mgr, BlockManager) | ||
assert isinstance(self._mgr, BlockManager) |
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.
since this is in the if
check above, not needed to repeat 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.
Thought so as well, but mypy disagrees
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.
Ah .. When do we use a cast
and when an assert
to deal with such issues?
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 prefer the assert here, but not sure if there is a general rule
Edit: I prefer assert not cast, stupid mistake in the initial post
Another thought here: now that we are limited to max 2 dimensions in NDFrame, isn't swapaxes just the same as transpose? (for the case i and j are not the same) We could then maybe also consolidate those implementations (eg swapaxes calling transpose when appropriate) |
Sounds good! But would take a look as follow up, the implementations are quite different and want to understand how this would impact stuff. I think transpose is better, as it keeps dtypes more often if possible |
# Conflicts: # pandas/core/generic.py
Merging for now, happy to address comments in a follow up if there are any |
doc/source/whatsnew/vX.X.X.rst
file if fixing a bug or adding a new feature.