-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
WIP: Panel Transpose Cleanup #25958
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
WIP: Panel Transpose Cleanup #25958
Conversation
@@ -651,32 +650,24 @@ def _set_axis(self, axis, labels): | |||
self._data.set_axis(axis, labels) | |||
self._clear_item_cache() | |||
|
|||
def transpose(self, *args, **kwargs): | |||
def transpose(self, copy, valid_axes=[1, 0]): |
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.
Can you make the default valid_axes=None
and then handle as appropriate within the method? Mutable default arguments can lead to problems so probably best to avoid just to be safe.
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.
Great callout! Do you think better to define here or even just move this code to the DataFrame class?
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.
Not super familiar with this, so don't want my opinion to carry too much weight, but I think it'd be cleaner to push this back to the DataFrame
class and remove it from here entirely. If we're removing Panel.transpose
then I think DataFrame
is the only thing that uses this method, so seems more direct that way? Looks like Series
/Index
inherit from IndexOpsMixin
and sparse things have their own implementation, so should be safe to remove unless I'm forgetting something?
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 probably could move the "core" implementation into DataFrame
, but I would think we should keep a skeleton implementation on transpose
in NDFrame
(even simple as raise NotImplemented
, as transpose
is arguably something that should be part of the implementation of anything that inherits from this base class).
Should also mention that this is somewhat of an "optional" cleanup. What brought me here was seeing At the end of the day Panel could simply be removed and no change, but I figure this is worth cleaning up to simplify is possible |
@WillAyd : I understand what you're trying to do, but the motivation for having those "kwargs" and "args" in the signature was for If this is just cleanup, I would just make sure we can separate out this method so that we can cleanly take it out for |
Do you know if there was an issue attached to that? Without knowing the backstory just looking at the current implementation it seems like there's a lot of unnecessary code and strange error reporting with what's in place, so I think worth revisiting if maybe the compatibility piece was only applicable to older versions. AFAICT the keyword arguments only ever make their way to the call to |
@WillAyd : By compatibility, it means compatibility with
It's been awhile, but if you'd like to dive into the history, you can go in a lot of directions from this PR I wrote then: #12810 |
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.
not sure i understand the purpose of this PR. We can simply remove the use of Panel for transpose rather than actually change what you are doing.
Mostly just trying to simplify existing code. Can always tackle later.
…Sent from my iPhone
On Apr 2, 2019, at 5:26 AM, Jeff Reback ***@***.***> wrote:
@jreback requested changes on this pull request.
not sure i understand the purpose of this PR. We can simply remove the use of Panel for transpose rather than actually change what you are doing.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I am not sure this does anything except add confusion. would rather just remove Panel methods / whole section that do this. |
Progress towards #25632
Prefacing this PR with the statement that this is pretty wonky, but I would consider that largely an artifact of cleaning up the existing code base.
Right now
transpose
is defined inNDFrame
but is only used byDataFrame
andPanel
, asSeries
objects end up using a separatetranspose
defined inIndexOpsMixin
.There are duplicate calls to
validate_transpose*
with various signatures that aren't well defined, and everything is passed rather ambiguously via args and kwargs which makes validation rather difficult.Existing validation is arguably rough. Here's a sample call and response on master:
As you can see the error message mentions the 'axes' parameter, but that isn't part of the signature of
transpose
and is instead ambiguously defined based off of args.What I've done here is removed the Panel implementation and tried to make the
NDFrame
implementation more explicit. Because it's only used byDataFrame
however, an alternate and arguably preferable implementation would be to raiseNotImplementedError
inNDFrame
and handle everything in theDataFrame
implementation once Panel is gone