Skip to content

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

Merged
merged 7 commits into from
Jan 4, 2022

Conversation

johnzangwill
Copy link
Contributor

Copy link
Member

@phofl phofl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small comments

@@ -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
Copy link
Member

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

Copy link
Contributor Author

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
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -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`)
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hopefully done.

Copy link
Contributor

@jreback jreback left a 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

@pep8speaks
Copy link

pep8speaks commented Jan 4, 2022

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

@johnzangwill
Copy link
Contributor Author

@johnzangwill johnzangwill requested review from jreback and phofl January 4, 2022 11:41
@jreback jreback added this to the 1.4 milestone Jan 4, 2022
@jreback jreback merged commit d06fb91 into pandas-dev:master Jan 4, 2022
@jreback
Copy link
Contributor

jreback commented Jan 4, 2022

thanks @johnzangwill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: MultiIndex dtypes incorrect if level names not unique
4 participants