@@ -2234,10 +2234,34 @@ def set_index(
22342234 col_ids_strs : List [str ] = [col_id for col_id in col_ids if col_id is not None ]
22352235 return DataFrame (self ._block .set_index (col_ids_strs , append = append , drop = drop ))
22362236
2237- @validations . requires_index
2237+ @overload # type: ignore[override]
22382238 def sort_index (
2239- self , ascending : bool = True , na_position : Literal ["first" , "last" ] = "last"
2239+ self ,
2240+ * ,
2241+ ascending : bool = ...,
2242+ inplace : Literal [False ] = ...,
2243+ na_position : Literal ["first" , "last" ] = ...,
22402244 ) -> DataFrame :
2245+ ...
2246+
2247+ @overload
2248+ def sort_index (
2249+ self ,
2250+ * ,
2251+ ascending : bool = ...,
2252+ inplace : Literal [True ] = ...,
2253+ na_position : Literal ["first" , "last" ] = ...,
2254+ ) -> None :
2255+ ...
2256+
2257+ @validations .requires_index
2258+ def sort_index (
2259+ self ,
2260+ * ,
2261+ ascending : bool = True ,
2262+ inplace : bool = False ,
2263+ na_position : Literal ["first" , "last" ] = "last" ,
2264+ ) -> Optional [DataFrame ]:
22412265 if na_position not in ["first" , "last" ]:
22422266 raise ValueError ("Param na_position must be one of 'first' or 'last'" )
22432267 na_last = na_position == "last"
@@ -2248,16 +2272,46 @@ def sort_index(
22482272 else order .descending_over (column , na_last )
22492273 for column in index_columns
22502274 ]
2251- return DataFrame (self ._block .order_by (ordering ))
2275+ block = self ._block .order_by (ordering )
2276+ if inplace :
2277+ self ._set_block (block )
2278+ return None
2279+ else :
2280+ return DataFrame (block )
22522281
2282+ @overload # type: ignore[override]
22532283 def sort_values (
22542284 self ,
22552285 by : str | typing .Sequence [str ],
22562286 * ,
2287+ inplace : Literal [False ] = ...,
2288+ ascending : bool | typing .Sequence [bool ] = ...,
2289+ kind : str = ...,
2290+ na_position : typing .Literal ["first" , "last" ] = ...,
2291+ ) -> DataFrame :
2292+ ...
2293+
2294+ @overload
2295+ def sort_values (
2296+ self ,
2297+ by : str | typing .Sequence [str ],
2298+ * ,
2299+ inplace : Literal [True ] = ...,
2300+ ascending : bool | typing .Sequence [bool ] = ...,
2301+ kind : str = ...,
2302+ na_position : typing .Literal ["first" , "last" ] = ...,
2303+ ) -> None :
2304+ ...
2305+
2306+ def sort_values (
2307+ self ,
2308+ by : str | typing .Sequence [str ],
2309+ * ,
2310+ inplace : bool = False ,
22572311 ascending : bool | typing .Sequence [bool ] = True ,
22582312 kind : str = "quicksort" ,
22592313 na_position : typing .Literal ["first" , "last" ] = "last" ,
2260- ) -> DataFrame :
2314+ ) -> Optional [ DataFrame ] :
22612315 if isinstance (by , (bigframes .series .Series , indexes .Index , DataFrame )):
22622316 raise KeyError (
22632317 f"Invalid key type: { type (by ).__name__ } . Please provide valid column name(s)."
@@ -2287,7 +2341,12 @@ def sort_values(
22872341 if is_ascending
22882342 else order .descending_over (column_id , na_last )
22892343 )
2290- return DataFrame (self ._block .order_by (ordering ))
2344+ block = self ._block .order_by (ordering )
2345+ if inplace :
2346+ self ._set_block (block )
2347+ return None
2348+ else :
2349+ return DataFrame (block )
22912350
22922351 def eval (self , expr : str ) -> DataFrame :
22932352 import bigframes .core .eval as bf_eval
0 commit comments