@@ -1769,7 +1769,7 @@ def sort_values(
17691769 axis = ...,
17701770 inplace : Literal [True ] = ...,
17711771 ascending : bool | typing .Sequence [bool ] = ...,
1772- kind : str = ...,
1772+ kind : str | None = ...,
17731773 na_position : typing .Literal ["first" , "last" ] = ...,
17741774 ) -> None : ...
17751775
@@ -1780,7 +1780,7 @@ def sort_values(
17801780 axis = ...,
17811781 inplace : Literal [False ] = ...,
17821782 ascending : bool | typing .Sequence [bool ] = ...,
1783- kind : str = ...,
1783+ kind : str | None = ...,
17841784 na_position : typing .Literal ["first" , "last" ] = ...,
17851785 ) -> Series : ...
17861786
@@ -1790,19 +1790,21 @@ def sort_values(
17901790 axis = 0 ,
17911791 inplace : bool = False ,
17921792 ascending = True ,
1793- kind : str = "quicksort" ,
1793+ kind : str | None = None ,
17941794 na_position : typing .Literal ["first" , "last" ] = "last" ,
17951795 ) -> Optional [Series ]:
17961796 if axis != 0 and axis != "index" :
17971797 raise ValueError (f"No axis named { axis } for object type Series" )
17981798 if na_position not in ["first" , "last" ]:
17991799 raise ValueError ("Param na_position must be one of 'first' or 'last'" )
1800+ is_stable = (kind or constants .DEFAULT_SORT_KIND ) in ["stable" , "mergesort" ]
18001801 block = self ._block .order_by (
18011802 [
18021803 order .ascending_over (self ._value_column , (na_position == "last" ))
18031804 if ascending
18041805 else order .descending_over (self ._value_column , (na_position == "last" ))
18051806 ],
1807+ stable = is_stable ,
18061808 )
18071809 if inplace :
18081810 self ._set_block (block )
@@ -1812,17 +1814,37 @@ def sort_values(
18121814
18131815 @typing .overload # type: ignore[override]
18141816 def sort_index (
1815- self , * , axis = ..., inplace : Literal [False ] = ..., ascending = ..., na_position = ...
1816- ) -> Series : ...
1817+ self ,
1818+ * ,
1819+ axis = ...,
1820+ inplace : Literal [False ] = ...,
1821+ ascending = ...,
1822+ kind : str | None = ...,
1823+ na_position = ...,
1824+ ) -> Series :
1825+ ...
18171826
18181827 @typing .overload
18191828 def sort_index (
1820- self , * , axis = 0 , inplace : Literal [True ] = ..., ascending = ..., na_position = ...
1821- ) -> None : ...
1829+ self ,
1830+ * ,
1831+ axis = 0 ,
1832+ inplace : Literal [True ] = ...,
1833+ ascending = ...,
1834+ kind : str | None = ...,
1835+ na_position = ...,
1836+ ) -> None :
1837+ ...
18221838
18231839 @validations .requires_index
18241840 def sort_index (
1825- self , * , axis = 0 , inplace : bool = False , ascending = True , na_position = "last"
1841+ self ,
1842+ * ,
1843+ axis = 0 ,
1844+ inplace : bool = False ,
1845+ ascending = True ,
1846+ kind : str | None = None ,
1847+ na_position = "last" ,
18261848 ) -> Optional [Series ]:
18271849 # TODO(tbergeron): Support level parameter once multi-index introduced.
18281850 if axis != 0 and axis != "index" :
@@ -1837,7 +1859,8 @@ def sort_index(
18371859 else order .descending_over (column , na_last )
18381860 for column in block .index_columns
18391861 ]
1840- block = block .order_by (ordering )
1862+ is_stable = (kind or constants .DEFAULT_SORT_KIND ) in ["stable" , "mergesort" ]
1863+ block = block .order_by (ordering , stable = is_stable )
18411864 if inplace :
18421865 self ._set_block (block )
18431866 return None
0 commit comments