Closed gurukiran07 closed 3 years ago
[X] I have checked that this issue has not already been reported.
[X] (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. https://github.com/pandas-dev/pandas/blob/03e1c899077d335a057a3f36c09645499638d417/pandas/core/indexes/multi.py#L703-L710
MultiIndex.dtypes
If level has no name then, level.name would be None.
level
level.name
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).
level_0
level_1
reset_index
level_x
@jreback @arw2019
Thanks @gurukiran07 for the report. PR to fix welcome.
@simonjayhawkins Made a PR #38582
[X] I have checked that this issue has not already been reported.
[X] (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. https://github.com/pandas-dev/pandas/blob/03e1c899077d335a057a3f36c09645499638d417/pandas/core/indexes/multi.py#L703-L710If
level
has no name then,level.name
would beNone
.Example where it fails:
When level is unamed i.e
None
may be we can addlevel_0
,level_1
etc. this would be consistent with API too(reset_index
would addlevel_x
).@jreback @arw2019