ascending must be a bool value
Package:
pandas
30911

Exception Class:
TypeError
Raise code
if isinstance(ascending, list):
if len(ascending) != 1:
raise TypeError("ascending must be a list of bool values of length 1")
ascending = ascending[0]
if not isinstance(ascending, bool):
raise TypeError("ascending must be a bool value")
return self.sort_values(return_indexer=True, ascending=ascending)
def _get_level_values(self, level) -> Index:
"""
Return an Index of values for requested level.
"""
Links to the raise (1)
https://github.com/pandas-dev/pandas/blob/b3e335254f46a526ee3ce9bb757eac4011d9d1fe/pandas/core/indexes/base.py#L1764Ways to fix
Summary:
This exception is thrown when the sortlevel function is called on an instance of Index from pandas. This function has an optional parameter for ascending that must be set equal to a Boolean. If it is set equal to anything else the exception will be thrown. Therefore in order to avoid any potential problems, ensure ascending is set to True or False, or leave it unchanged because it is set to True by default.
Code to Reproduce the Error (Wrong):
from pandas.core.indexes.base import Index
lst = [1,2,3]
i = Index(lst)
i.sortlevel(0, ["f"])
Error Message:
TypeError Traceback (most recent call last)
<ipython-input-6-becd787a3ffe> in <module>()
2 lst = [1,2,3]
3 i = Index(lst)
----> 4 i.sortlevel(0, ["f"])
/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py in sortlevel(self, level, ascending, sort_remaining)
1765
1766 if not isinstance(ascending, bool):
-> 1767 raise TypeError("ascending must be a bool value")
1768
1769 return self.sort_values(return_indexer=True, ascending=ascending)
TypeError: ascending must be a bool value
Working Version:
from pandas.core.indexes.base import Index
lst = [1,2,3]
i = Index(lst)
i.sortlevel(0, False)
Add a possible fix
Please authorize to post fix