Skip to content

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

Closed
@TomAugspurger

Description

@TomAugspurger

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')

Metadata

Metadata

Assignees

Labels

API - ConsistencyInternal Consistency of API/BehaviorIndexRelated to the Index class or subclassesMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolategood first issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions