Skip to content

bool(MultiIndex) seems to always return False #7897

Closed
@langmore

Description

@langmore

This means that patterns such as:

if my_frame.index:
    # do something

with my_frame having a MultiIndex will never enter the if block. One can check that bool(my_frame.index) returns False. A single index (pandas.Index) will (correctly IMO) raise a ValueError warning that the truth value of an array is ambiguous. However, a MultiIndex fails silently.

This is such an awesome source of silent bugs that I'm surprised this hasn't come up before. Is there any reason why we want bool to return False every time for a MultiIndex?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions