pandas: ENH: Raise error on ascending='False'
Is your feature request related to a problem?
when sort_values ascending parameter is set to a string (df.sort_values(col_name, ascending=‘False’) it does not error although it’s meaningless, this could be quite confusing.
Describe the solution you’d like
Raise an error if ascending is equal to values that are not boolean
API breaking implications
Error raising
Describe alternatives you’ve considered
Warning is also good, but I think error makes more sense
Additional context
for an hour I was wondering why ascending=‘False’ is not working
isinstance('False', bool) :)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 15 (3 by maintainers)
Commits related to this issue
- BUG: Dataframe.sort_values not raising ValueError for ascending-incompatible value (#41634) — committed to gaikwadrahul20/pandas by gaikwadrahul20 3 years ago
- BUG: Series.sort_values not raising ValueError for ascending-incompatible value (#41634) — committed to gaikwadrahul20/pandas by gaikwadrahul20 3 years ago
You can use sorted() function here. Code:
Output:
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']