@@ -104,18 +104,13 @@ def test_sort_index_multiindex(self, level):
104
104
res = s .sort_index (level = level , sort_remaining = False )
105
105
tm .assert_series_equal (s , res )
106
106
107
- def test_sort_index_kind (self ):
107
+ @pytest .mark .parametrize ("kind" , ["quicksort" , "mergesort" , "heapsort" , "stable" ])
108
+ def test_sort_index_kind (self , kind ):
108
109
# GH#14444 & GH#13589: Add support for sort algo choosing
109
110
series = Series (index = [3 , 2 , 1 , 4 , 3 ], dtype = object )
110
111
expected_series = Series (index = [1 , 2 , 3 , 3 , 4 ], dtype = object )
111
112
112
- index_sorted_series = series .sort_index (kind = "mergesort" )
113
- tm .assert_series_equal (expected_series , index_sorted_series )
114
-
115
- index_sorted_series = series .sort_index (kind = "quicksort" )
116
- tm .assert_series_equal (expected_series , index_sorted_series )
117
-
118
- index_sorted_series = series .sort_index (kind = "heapsort" )
113
+ index_sorted_series = series .sort_index (kind = kind )
119
114
tm .assert_series_equal (expected_series , index_sorted_series )
120
115
121
116
def test_sort_index_na_position (self ):
@@ -251,32 +246,22 @@ def test_sort_index_key_int(self):
251
246
result = series .sort_index (key = lambda x : 2 * x )
252
247
tm .assert_series_equal (result , series )
253
248
254
- def test_sort_index_kind_key (self , sort_by_key ):
249
+ @pytest .mark .parametrize ("kind" , ["quicksort" , "mergesort" , "heapsort" , "stable" ])
250
+ def test_sort_index_kind_key (self , kind , sort_by_key ):
255
251
# GH #14444 & #13589: Add support for sort algo choosing
256
252
series = Series (index = [3 , 2 , 1 , 4 , 3 ], dtype = object )
257
253
expected_series = Series (index = [1 , 2 , 3 , 3 , 4 ], dtype = object )
258
254
259
- index_sorted_series = series .sort_index (kind = "mergesort" , key = sort_by_key )
260
- tm .assert_series_equal (expected_series , index_sorted_series )
261
-
262
- index_sorted_series = series .sort_index (kind = "quicksort" , key = sort_by_key )
255
+ index_sorted_series = series .sort_index (kind = kind , key = sort_by_key )
263
256
tm .assert_series_equal (expected_series , index_sorted_series )
264
257
265
- index_sorted_series = series .sort_index (kind = "heapsort" , key = sort_by_key )
266
- tm .assert_series_equal (expected_series , index_sorted_series )
267
-
268
- def test_sort_index_kind_neg_key (self ):
258
+ @pytest .mark .parametrize ("kind" , ["quicksort" , "mergesort" , "heapsort" , "stable" ])
259
+ def test_sort_index_kind_neg_key (self , kind ):
269
260
# GH #14444 & #13589: Add support for sort algo choosing
270
261
series = Series (index = [3 , 2 , 1 , 4 , 3 ], dtype = object )
271
262
expected_series = Series (index = [4 , 3 , 3 , 2 , 1 ], dtype = object )
272
263
273
- index_sorted_series = series .sort_index (kind = "mergesort" , key = lambda x : - x )
274
- tm .assert_series_equal (expected_series , index_sorted_series )
275
-
276
- index_sorted_series = series .sort_index (kind = "quicksort" , key = lambda x : - x )
277
- tm .assert_series_equal (expected_series , index_sorted_series )
278
-
279
- index_sorted_series = series .sort_index (kind = "heapsort" , key = lambda x : - x )
264
+ index_sorted_series = series .sort_index (kind = kind , key = lambda x : - x )
280
265
tm .assert_series_equal (expected_series , index_sorted_series )
281
266
282
267
def test_sort_index_na_position_key (self , sort_by_key ):
0 commit comments