Skip to content

BUG: In Multilevel.dtypes when level name is not specified it gives wrong output #38580

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

Closed
2 tasks done
gurukiran07 opened this issue Dec 19, 2020 · 2 comments · Fixed by #38582
Closed
2 tasks done

BUG: In Multilevel.dtypes when level name is not specified it gives wrong output #38580

gurukiran07 opened this issue Dec 19, 2020 · 2 comments · Fixed by #38582
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions MultiIndex
Milestone

Comments

@gurukiran07
Copy link
Contributor

gurukiran07 commented Dec 19, 2020

  • I have checked that this issue has not already been reported.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


There was a recent PR to add MultiIndex.dtypes #37073 but this only works when each level is named.

@cache_readonly
def dtypes(self) -> "Series":
"""
Return the dtypes as a Series for the underlying MultiIndex
"""
from pandas import Series
return Series({level.name: level.dtype for level in self.levels})

If level has no name then, level.name would be None.

Example where it fails:

idx_multitype = pd.MultiIndex.from_product(
     [[1, 2, 3], ["a", "b", "c"], pd.date_range("20200101", periods=2, tz="UTC")],
 )
{level.name: level.dtype for level in idx_multitype.levels}
# {None: datetime64[ns, UTC]}

When level is unamed i.e None may be we can add level_0, level_1 etc. this would be consistent with API too(reset_index would add level_x).

@jreback
@arw2019

@gurukiran07 gurukiran07 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 19, 2020
@gurukiran07 gurukiran07 changed the title BUG: BUG: In Multilevel.dtypes when level is not specified it gives wrong output Dec 19, 2020
@gurukiran07 gurukiran07 changed the title BUG: In Multilevel.dtypes when level is not specified it gives wrong output BUG: In Multilevel.dtypes when level name is not specified it gives wrong output Dec 19, 2020
@simonjayhawkins simonjayhawkins added Dtype Conversions Unexpected or buggy dtype conversions MultiIndex and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 19, 2020
@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Dec 19, 2020
@simonjayhawkins
Copy link
Member

Thanks @gurukiran07 for the report. PR to fix welcome.

@gurukiran07
Copy link
Contributor Author

@simonjayhawkins Made a PR #38582

@jreback jreback modified the milestones: Contributions Welcome, 1.3 Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dtype Conversions Unexpected or buggy dtype conversions MultiIndex
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants