Skip to content

Series.sort_values using mergesort and descending is not stable #28697

Closed
@has2k1

Description

@has2k1

Code Sample

import pandas as pd

s = pd.Series([1, 2, 1, 3], ['first', 'b', 'second', 'c'])
print(s.sort_values(ascending=False, kind='mergesort'))

Output

c         3
b         2
second    1
first     1
dtype: int64

Expected Output

c         3
b         2
first     1
second    1
dtype: int64

Problem description

Mergesort should be stable irrespective of direction, but ascending=False (which is not stable) is just the reverse of ascending=True (which is stable).

Metadata

Metadata

Assignees

Labels

AlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffNeeds TestsUnit test(s) needed to prevent regressionsgood first issue

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions