question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pandas.Series.sort_values(ascending=[False]) behaves as ascending=True

See original GitHub issue

Code 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()

# Paste the output here pd.show_versions() here INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Windows OS-release: 7 machine: AMD64 processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel byteorder: little LC_ALL: None LANG: en LOCALE: None.None

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:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MLopez-Ibanezcommented, Mar 7, 2017

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.

0reactions
jrebackcommented, Mar 7, 2017

yes would accept a patch and leave the api (iow accept a 1-element list of a boolean); would need a touch of validation

On Mar 7, 2017, at 2:15 PM, MLopez-Ibanez notifications@github.com wrote:

Thanks. Does this mean that you may accept a patch making ascending=[False] behave the same as ascending=False ?

I don’t want to waste our time if there is some reason unknown to me why this is undesired behavior. Perhaps there are performance issues in that case that I cannot imagine at the moment.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas.Series.sort_values — pandas 1.5.2 documentation
Parameter needed for compatibility with DataFrame. ascendingbool or list of bools, default True. If True, sort values in ascending order, otherwise descending.
Read more >
Pandas Series.sort_values() With Examples
pandas Series.sort_values() function is used to sort values on Series object. It sorts the series in ascending order or descending order, by default...
Read more >
The Quickest Ways to Sort Pandas DataFrame Values - Kite
Perform sorting functions in the Pandas DataFrame. Learn Pandas sort_values and sort_index., plus 7 top use cases with examples.
Read more >
The Pandas DataFrame: Make Working With Data Delightful
Pandas DataFrame Labels as Sequences; Data as NumPy Arrays; Data Types ... df.sort_values(by='js-score', ascending=False) name city py-score django-score ...
Read more >
Python | Pandas Series.sort_values() - GeeksforGeeks
The function also provides the flexibility of choosing the sorting algorithm. Syntax: Series.sort_values(axis=0, ascending=True, inplace=False, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found