Skip to content

BUG: Regression in sort_index with ascending=None #39434

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
2 of 3 tasks
YarShev opened this issue Jan 27, 2021 · 8 comments · Fixed by #39451
Closed
2 of 3 tasks

BUG: Regression in sort_index with ascending=None #39434

YarShev opened this issue Jan 27, 2021 · 8 comments · Fixed by #39451
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@YarShev
Copy link
Contributor

YarShev commented Jan 27, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

# Your code here
import pandas
import numpy as np
df = pandas.DataFrame(np.arange(64))
length = len(df.index)
df.index = [(i - length / 2) % length for i in range(length)]
df.sort_index(axis=0, ascending=None, na_position="first")
ValueError: the 'axis' parameter is not supported in the pandas implementation of argsort()

Problem description

There was no such issue in pandas version 1.1.5

Output of pd.show_versions()

pandas : 1.2.1
numpy : 1.19.5
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.1.2.post20210112
Cython : None
pytest : 6.2.1
hypothesis : None
sphinx : None
blosc : None
feather : 0.4.1
xlsxwriter : None
lxml.etree : 4.6.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.12.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : None
fsspec : 0.8.3
fastparquet : None
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.7.2
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : 2.0.0
pyxlsb : None
s3fs : 0.5.2
scipy : 1.6.0
sqlalchemy : 1.3.22
tables : 3.6.1
tabulate : None
xarray : 0.16.2
xlrd : 2.0.1
xlwt : None
numba : None

@YarShev YarShev added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 27, 2021
@YarShev
Copy link
Contributor Author

YarShev commented Jan 27, 2021

The same is true for Series.sort_index(...).

@attack68
Copy link
Contributor

ascending is an argument which accepts boolean or list of booleans. I do not believe it should be considered a bug or a regression if the execution has changed from one version to another with an erroneous input argument.

I would not know what output to expect with ascending=None?

@jreback
Copy link
Contributor

jreback commented Jan 27, 2021

we should be validating the ascending arg type as boolean - it's possible we r not

@YarShev
Copy link
Contributor Author

YarShev commented Jan 27, 2021

I would not know what output to expect with ascending=None?

As I see, ascending=None and ascending=False behaviors were identical in 1.1.5 version. So, I think it would be good to add a check for ascending.

@jreback jreback added Reshaping Concat, Merge/Join, Stack/Unstack, Explode and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Jan 28, 2021
@jreback jreback added this to the 1.2.2 milestone Jan 28, 2021
@simonjayhawkins
Copy link
Member

moving to 1.2.3

@simonjayhawkins simonjayhawkins modified the milestones: 1.2.2, 1.2.3 Feb 8, 2021
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Feb 8, 2021
@simonjayhawkins
Copy link
Member

There was no such issue in pandas version 1.1.5

first bad commit: [aa43f17] REF: nargsort incorrectly calling _values_for_argsort (#37266)

As I see, ascending=None and ascending=False behaviors were identical in 1.1.5 version. So, I think it would be good to add a check for ascending.

@ivanovmg an alternative could be to restore the old behaviour for 1.2.x and repurpose #39451 for 1.3 and then can advertise the 'breaking change', which is permissible since the usage is incorrect.

@jreback
Copy link
Contributor

jreback commented Feb 8, 2021

no i think we should just fix this - the. new is wrong

@ivanovmg
Copy link
Member

@jreback @simonjayhawkins
Can you please clarify what will be the preferable way?
Should I restore the old behavior in nargsort as @simonjayhawkins recommends?
@jreback it is not clear for my what you suggest here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants