pandas.Series.sort_values(ascending=[False]) behaves as ascending=True
See original GitHub issueCode Sample, a copy-pastable example if possible
# Your code here
import pandas as pd
x = pd.Series([4,5,6,1,2,3])
print(x.sort_values(ascending=False))
print(x.sort_values(ascending=[False]))
Problem description
False and [False] behave differently. They should behave in the same way according to the documentation (and it makes sense that they do).
Expected Output
2 6 1 5 0 4 5 3 4 2 3 1 dtype: int64 2 6 1 5 0 4 5 3 4 2 3 1 dtype: int64
Output of pd.show_versions()
pandas: 0.19.2 nose: 1.3.7 pip: 9.0.1 setuptools: 27.2.0 Cython: 0.25.2 numpy: 1.11.3 scipy: 0.18.1 statsmodels: 0.6.1 xarray: None IPython: 5.1.0 sphinx: 1.5.1 patsy: 0.4.1 dateutil: 2.6.0 pytz: 2016.10 blosc: None bottleneck: 1.2.0 tables: 3.2.2 numexpr: 2.6.1 matplotlib: 2.0.0 openpyxl: 2.4.1 xlrd: 1.0.0 xlwt: 1.2.0 xlsxwriter: 0.9.6 lxml: 3.7.2 bs4: 4.5.3 html5lib: None httplib2: None apiclient: None sqlalchemy: 1.1.5 pymysql: None psycopg2: None jinja2: 2.9.4 boto: 2.45.0 pandas_datareader: None
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top GitHub Comments
Shouldn’t operations on similar types behave as uniformly as possible? One should not need to know what x is or even what the argument of ascending is, it should just work. Thus, one should be able to write something like:
z.sort_values(ascending = order)
and it should do the right thing whether x is a Series or a 1-column DataFrame. Otherwise, users need to either special case for Series vs. DataFrame or special case for 1-column versus n-columns.
yes would accept a patch and leave the api (iow accept a 1-element list of a boolean); would need a touch of validation