bool(MultiIndex) seems to always return False · Issue #7897 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
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
?