Skip to content

BUG: DataFrame.sort_values doesn't validate type of ascendind #42434

@datapythonista

Description

@datapythonista

xref #42358

See the next code (and ascending provided as a string, not boolean):

>>> pandas.DataFrame({'col': [3, 1, 2]}).sort_values(by='col', ascending='False')
   col
1    1
2    2
0    3

This should fail in the same way as in Series:

>>> pandas.Series([3, 1, 2]).sort_values(ascending='False')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-f05e80474e4f> in <module>
----> 1 pandas.Series([3, 1, 2]).sort_values(ascending='False')

~/miniconda3/envs/ibis-dev/lib/python3.7/site-packages/pandas/core/series.py in sort_values(self, axis, ascending, inplace, kind, na_position, ignore_index, key)
   3254 
   3255         if not is_bool(ascending):
-> 3256             raise ValueError("ascending must be boolean")
   3257 
   3258         if na_position not in ["first", "last"]:

ValueError: ascending must be boolean

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions