-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Return the right class, when subclassing a DataFrame with multi-level index #9632
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
needs tests |
What to test for, @jreback ? I can test, if subclassing works correctly, but there are other open issues on this topic and I understand it's work in progress. |
well you need to assert that the correct class is returned you create a dummy class do the operation and assert not sure what you mean by the rest of your statement - exactly what doesn't work? |
You're right. That's something that can be tested. I'll just add the use cases that were broken before. Thanks for the pointer. |
whats new is now available for 0.16.1 5ebf521 |
Great. Now it pulled in some other commits as well. Is that an issue? |
@manuelRiel If you do:
this should solve the extra commits |
Yes. That did the trick. Usually I do a feature branch, but I forgot this time. So the PR is ok now? |
@manuelRiel you need to |
Cleaned out the extra commits. We're good now? |
@@ -2751,6 +2751,52 @@ def test_insert_error_msmgs(self): | |||
with assertRaisesRegexp(TypeError, msg): | |||
df['gr'] = df.groupby(['b', 'c']).count() | |||
|
|||
def test_frame_subclassing_and_slicing(self): | |||
# Subclass frame and ensure it returns the right class on slicing it |
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.
add the issue (this pr number is ok) as a comment
pls add a release note in v0.16.1 (you can put in API changes). @sinhrks can you take a look |
Thanks for the heads up, guys. I have added the reference to the PR, as well as the release note. Let me know, if there is anything else to change. |
@@ -27,7 +27,7 @@ Enhancements | |||
API changes | |||
~~~~~~~~~~~ | |||
|
|||
|
|||
- When subclassing ``DataFrame``, the correct class is returned, as specified in ``_constructor_sliced`` |
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.
add this the PR number as well (as there isn't an issue number)
pls rebase / squash, see here for help |
Done @jreback |
@manuelRiel Thanks for the fix. Can you prepare test cases when the column is
|
Sure. I'll look into that. We're using multi-levels extensively and didn't run into issues. But it's possible I overrode this function in the subclass. I'll make sure it works properly. |
Added the tests, @sinhrks . Returns custom class as expected. |
@@ -27,7 +27,7 @@ Enhancements | |||
API changes | |||
~~~~~~~~~~~ | |||
|
|||
|
|||
- When subclassing ``DataFrame``, the correct class is returned, as specified in ``_constructor_sliced`` (PR 9632) |
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.
Test lgtm. I think the issue is classified as a bug rather than API change. Can you describe a occurrence condition briefly, and refer to the issue as the same style as others (pls correct my English...)?
- Bug in subclassed ``DataFrame`` with ``MultiIndex`` columns may not return correct class (:issue:`9632`)
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.
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.
Is the wording below acceptable, @sinhrks ? I'll put that under Bug fixes
- Bug in subclassed
DataFrame
with our withoutMultiIndex
may not return the correct class, when slicing or subsetting it. (:issue:2859
, :issue:9632
)
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.
Thanks, I think only referring to #9632 is enough (as 2859 has been closed already).
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.
Committed as discussed.
@manuelRiel this looks fine. Can you rebase and ping on green. |
Rebased and passing, @jreback |
Return the right class, when subclassing a DataFrame with multi-level index
@manuelRiel thanks! |
Subclassing pandas.DataFrame had some issues, when a multi-level index was used. This PR should fix that.