Skip to content

Index.sort_values puts missing values at the start with ascending=False #31220

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
TomAugspurger opened this issue Jan 22, 2020 · 5 comments
Closed
Assignees
Labels
API - Consistency Internal Consistency of API/Behavior good first issue Index Related to the Index class or subclasses Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Comments

@TomAugspurger
Copy link
Contributor

Code Sample, a copy-pastable example if possible

Index.sort_values places missing values at the start of the result with ascending=False

In [4]: pd.Index([1, np.nan, 0]).sort_values(ascending=False)
Out[4]: Float64Index([nan, 1.0, 0.0], dtype='float64')

In [5]: pd.Series([1, np.nan, 0]).sort_values(ascending=False)
Out[5]:
0    1.0
2    0.0
1    NaN
dtype: float64

Problem description

This differs from Series.sort_values, which always leaves NA values at the end.

Expected Output

Out[4]: Float64Index([1.0, 0.0, nan], dtype='float64')
@dsaxton
Copy link
Member

dsaxton commented Jan 22, 2020

Should Index.sort_values also have an na_position argument? It looks like it just uses Index.argsort whereas Series handles the NA values separately according to na_position.

@Dr-Irv Dr-Irv added API - Consistency Internal Consistency of API/Behavior Index Related to the Index class or subclasses labels Sep 5, 2020
@Dr-Irv
Copy link
Contributor

Dr-Irv commented Sep 5, 2020

Agree with @dsaxton above

@Dr-Irv Dr-Irv added good first issue Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate labels Sep 5, 2020
@junjunjunk
Copy link
Contributor

take

@junjunjunk
Copy link
Contributor

junjunjunk commented Sep 20, 2020

This issue has already resolved.
#35604
ba552ec#diff-248241e14f081931cc805f9d0e137a5f

@dsaxton
Copy link
Member

dsaxton commented Sep 20, 2020

@junjunjunk I think you're right. Looks like this was implemented with tests added, so this can be closed

@dsaxton dsaxton closed this as completed Sep 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior good first issue Index Related to the Index class or subclasses Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

No branches or pull requests

4 participants