-
- Notifications
You must be signed in to change notification settings - Fork 19.4k
Open
Labels
BugError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasMultiIndex
Description
MultiIndexes with empty levels are valid, but set_levels does not account for that case:
index = pd.MultiIndex(levels=[[], []], labels=[[], []], names=['a', 'b']) index.set_levels([], level='a')The set_levels code that looks like
if is_list_like(levels[0]): raise TypeError("Levels must be list-like")should probably be
if len(levels) > 0 and is_list_like(levels[0]): raise TypeError("Levels must be list-like")While I'm looking at this, a couple other questiosn:
- How come we only check the first element? What if levels looks like
['a', ['b']]? I think we need to doany(is_list_like(x) for x in levels), which has the additional benefit that empty levels are handled correctly. - Can we make the
TypeErrormessage more precise? Maybe something likeValueError("Levels must not contain list-like items")
Metadata
Metadata
Assignees
Labels
BugError ReportingIncorrect or improved errors from pandasIncorrect or improved errors from pandasMultiIndex