Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MLopez-Ibanez opened this issue Mar 7, 2017 · 7 comments
Closed
Labels
Bug Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@MLopez-Ibanez
Copy link

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

@jreback
Copy link
Contributor

jreback commented Mar 7, 2017

this option is actually only for DataFrames. I doesn't make sense for Series (IOW only a bool should be accepted). So we should take it out. PR's welcome.

@jreback jreback added Bug Difficulty Novice Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Mar 7, 2017
@jreback jreback added this to the 0.20.0 milestone Mar 7, 2017
@MLopez-Ibanez
Copy link
Author

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.

@MLopez-Ibanez
Copy link
Author

MLopez-Ibanez commented Mar 7, 2017

Btw, I'm teaching Python to post-graduate students and one of the major pain points are minor differences between Series and DataFrames. It just confuses them to no end and they are incredibly smart students who are learning programming from zero knowledge in less than 4 months.

@MLopez-Ibanez
Copy link
Author

I'm also happy to contribute a fix towards making the behavior more uniform if you point me to the contributors checklist.

@jreback
Copy link
Contributor

jreback commented Mar 7, 2017

@jreback
Copy link
Contributor

jreback commented Mar 7, 2017

well this has a different API than DataFrame naturally

sorting in a dataframe can involve multiple columns ;on a series it cannot

ascending is a paired argument to it follows

happy to allow the listlike (len of 1) as well

@jreback
Copy link
Contributor

jreback commented Mar 7, 2017 via email

MLopez-Ibanez pushed a commit to MLopez-Ibanez/pandas that referenced this issue Mar 7, 2017
MLopez-Ibanez pushed a commit to MLopez-Ibanez/pandas that referenced this issue Mar 7, 2017
MLopez-Ibanez pushed a commit to MLopez-Ibanez/pandas that referenced this issue Mar 7, 2017
MLopez-Ibanez pushed a commit to MLopez-Ibanez/pandas that referenced this issue Mar 7, 2017
@jreback jreback closed this as completed in c9d4e0b Mar 8, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017
…alse (pandas-dev#15604)

closes pandas-dev#15604

Author: manu <[email protected]>

Closes pandas-dev#15607 from MLopez-Ibanez/series-ascending and squashes the following commits:

6678574 [manu] BUG: make Series.sort_values(ascending=[False]) behave as ascending=False (pandas-dev#15604)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error Reporting Incorrect or improved errors from pandas Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
2 participants