Skip to content

BUG: reset_index with NaN in MultiIndex #6322

Closed
@wangshun98

Description

@wangshun98

This is related to the following commit.
jreback@625ee94

When one level in the MultiIndex is all NaN, line 2819 in DataFrame.reset_index() and subfunction _maybe_cast, will have a problem, because values is empty.
2819: values = values.take(labels)
IndexError: cannot do a non-empty take from an empty axes

A possible fix is to add the following lines before 2819:
if mask.all():
values = labels * np.nan
return values

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolateMultiIndex

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions