-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: MultiIndex dtypes incorrect if level names not unique #45175
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
johnzangwill
commented
Jan 3, 2022
- closes BUG: MultiIndex dtypes incorrect if level names not unique #45174
- tests added / passed
- Ensure all linting tests pass, see here for how to run them
- whatsnew entry
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.
small comments
pandas/core/indexes/multi.py
Outdated
@@ -735,13 +735,14 @@ def array(self): | |||
def dtypes(self) -> Series: | |||
""" | |||
Return the dtypes as a Series for the underlying MultiIndex. | |||
|
|||
.. versionchanged:: 1.4.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.
I don't think that we need this, since this qualifies as a bug fix
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.
agree
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.
Done
@@ -67,6 +67,13 @@ def test_get_dtypes_no_level_name(): | |||
tm.assert_series_equal(expected, idx_multitype.dtypes) | |||
|
|||
|
|||
def test_get_dtypes_duplicate_level_names(): | |||
# Test MultiIndex.dtypes with non-unique level names (# GH45174 ) | |||
result = MultiIndex.from_arrays([[1], [2]], names=[1, 1]).dtypes |
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.
Could you also add a test with different dtypes?
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.
doc/source/whatsnew/v1.4.0.rst
Outdated
@@ -835,6 +835,7 @@ MultiIndex | |||
- Bug in :meth:`MultiIndex.get_loc` raising ``TypeError`` instead of ``KeyError`` on nested tuple (:issue:`42440`) | |||
- Bug in :meth:`MultiIndex.union` setting wrong ``sortorder`` causing errors in subsequent indexing operations with slices (:issue:`44752`) | |||
- Bug in :meth:`MultiIndex.putmask` where the other value was also a :class:`MultiIndex` (:issue:`43212`) | |||
- Bug in :meth:`MultiIndex.dtypes` when duplicate level names returned only one dtype (:issue:`45174`) |
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.
Could you clarify a bit? Maybe only one entry for all levels with same name. I though this would return a Series with the correct length but with the same dtype in every row
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.
Hopefully done.
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.
also pls add a test that exercises this
Hello @johnzangwill! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found: There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻 Comment last updated at 2022-01-04 12:35:34 UTC |
|
thanks @johnzangwill |