-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
Bugfix: Couldn't subclass Panel #888
Conversation
various methods were calling the Panel constructor instead of the _constructor method. Also from_dict was returning Panel objects instead of __class__ objects.
…cause" This reverts commit 5c8347b.
Panel instead of self.__class__ to construct modified objects.
@@ -320,7 +320,7 @@ def from_dict(cls, data, intersect=False, orient='items', dtype=None): | |||
data, index, columns = _homogenize_dict(data, intersect=intersect, | |||
dtype=dtype) | |||
items = Index(sorted(data.keys())) | |||
return Panel(data, items, index, columns) | |||
return __class__(data, items, index, columns) |
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.
Shouldn't this be cls
rather than __class__
?
Welcome to open source! You're on the right lines, I've just highlighted a few potential problems. Other people who're more familiar with the design of panel may give you more suggestions. Remember, although the comments might come across as quite terse, we are grateful that you're using and improving the code. |
Thanks for the feedback. I changed _constructor to return type(self), and the _constructorGroupBy thing was a consequence of sloppy search and replace, so I fixed that. Should I submit another request or keep this one? |
Merged in. Welcome to the project! Future reference, it's easier (on you) if you work in a non-master branch. When you update, you'll have to "git reset --hard /master" |
@joshuaar a more fundamental question is: why are you subclassing Panel? Often when people ask me about subclassing I talk them out of it (viz "favor composition over inheritance") |
I was trying to create a subclass from Panel and came into this snag. I'm not sure if there was a reason Panel was using a hard coded _constructor method, but I changed it to be more generic. I'm new to open source, so constructive criticism is welcome. Am I doing this right?