Skip to content

Commit 48fe4cb

Browse files
committed
Changes as requested in the review
1 parent 62af0bf commit 48fe4cb

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

doc/source/whatsnew/v0.25.2.rst

-3
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@ Other
102102
- Compatibility with Python 3.8 in :meth:`DataFrame.query` (:issue:`27261`)
103103
- Fix to ensure that tab-completion in an IPython console does not raise
104104
warnings for deprecated attributes (:issue:`27900`).
105-
- Bug in :meth:`Series.sort_values` when ``ascending`` is set to ``False`` and
106-
``kind`` is set to ``mergesort`` (:issue:`28697`)
107-
108105

109106
.. _whatsnew_0.252.contributors:
110107

doc/source/whatsnew/v1.0.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ Other
301301
- Using :meth:`DataFrame.replace` with overlapping keys in a nested dictionary will no longer raise, now matching the behavior of a flat dictionary (:issue:`27660`)
302302
- :meth:`DataFrame.to_csv` and :meth:`Series.to_csv` now support dicts as ``compression`` argument with key ``'method'`` being the compression method and others as additional compression options when the compression method is ``'zip'``. (:issue:`26023`)
303303
- :meth:`Series.append` will no longer raise a ``TypeError`` when passed a tuple of ``Series`` (:issue:`28410`)
304+
- Bug in :meth:`Series.sort_values` when ``ascending`` is set to ``False`` and
305+
``kind`` is set to ``mergesort`` (:issue:`28697`)
304306

305307
.. _whatsnew_1000.contributors:
306308

pandas/core/series.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -3079,9 +3079,7 @@ def sort_values(
30793079
raise ValueError("ascending must be boolean")
30803080

30813081
arr = self._values
3082-
indexer = nargsort(
3083-
arr, kind=kind, ascending=ascending, na_position=na_position
3084-
)
3082+
indexer = nargsort(arr, kind=kind, ascending=ascending, na_position=na_position)
30853083

30863084
result = self._constructor(arr[indexer], index=self.index[indexer])
30873085

pandas/tests/series/test_sorting.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,13 @@ def test_sort_values(self):
8686
with pytest.raises(ValueError, match=msg):
8787
s.sort_values(inplace=True)
8888

89-
# mergesort and ascending=False
89+
def test_sort_values_mergesort(self):
9090
ser = Series([1, 2, 1, 3], ["first", "b", "second", "c"])
91+
expected = Series([1, 1, 2, 3], ["first", "second", "b", "c"])
92+
result = ser.sort_values(kind="mergesort")
93+
tm.assert_series_equal(expected, result)
94+
95+
# ascending=False is not just a reverse of ascending=True
9196
expected = Series([3, 2, 1, 1], ["c", "b", "first", "second"])
9297
result = ser.sort_values(ascending=False, kind="mergesort")
9398
tm.assert_series_equal(expected, result)

0 commit comments

Comments
 (0)