3131 Literal ,
3232 Mapping ,
3333 Optional ,
34+ overload ,
3435 Sequence ,
3536 Tuple ,
3637 Union ,
@@ -95,6 +96,10 @@ class Series(bigframes.operations.base.SeriesMethods, vendored_pandas_series.Ser
9596 # Must be above 5000 for pandas to delegate to bigframes for binops
9697 __pandas_priority__ = 13000
9798
99+ # Ensure mypy can more robustly determine the type of self._block since it
100+ # gets set in various places.
101+ _block : blocks .Block
102+
98103 def __init__ (self , * args , ** kwargs ):
99104 self ._query_job : Optional [bigquery .QueryJob ] = None
100105 super ().__init__ (* args , ** kwargs )
@@ -254,22 +259,45 @@ def __iter__(self) -> typing.Iterator:
254259 def copy (self ) -> Series :
255260 return Series (self ._block )
256261
262+ @overload
257263 def rename (
258- self , index : Union [blocks .Label , Mapping [Any , Any ]] = None , ** kwargs
264+ self ,
265+ index : Union [blocks .Label , Mapping [Any , Any ]] = None ,
266+ ) -> Series :
267+ ...
268+
269+ @overload
270+ def rename (
271+ self ,
272+ index : Union [blocks .Label , Mapping [Any , Any ]] = None ,
273+ * ,
274+ inplace : Literal [False ],
275+ ** kwargs ,
259276 ) -> Series :
277+ ...
278+
279+ @overload
280+ def rename (
281+ self ,
282+ index : Union [blocks .Label , Mapping [Any , Any ]] = None ,
283+ * ,
284+ inplace : Literal [True ],
285+ ** kwargs ,
286+ ) -> None :
287+ ...
288+
289+ def rename (
290+ self ,
291+ index : Union [blocks .Label , Mapping [Any , Any ]] = None ,
292+ * ,
293+ inplace : bool = False ,
294+ ** kwargs ,
295+ ) -> Optional [Series ]:
260296 if len (kwargs ) != 0 :
261297 raise NotImplementedError (
262298 f"rename does not currently support any keyword arguments. { constants .FEEDBACK_LINK } "
263299 )
264300
265- # rename the Series name
266- if index is None or isinstance (
267- index , str
268- ): # Python 3.9 doesn't allow isinstance of Optional
269- index = typing .cast (Optional [str ], index )
270- block = self ._block .with_column_labels ([index ])
271- return Series (block )
272-
273301 # rename the index
274302 if isinstance (index , Mapping ):
275303 index = typing .cast (Mapping [Any , Any ], index )
@@ -294,22 +322,61 @@ def rename(
294322
295323 block = block .set_index (new_idx_ids , index_labels = block .index .names )
296324
297- return Series (block )
325+ if inplace :
326+ self ._block = block
327+ return None
328+ else :
329+ return Series (block )
298330
299331 # rename the Series name
300332 if isinstance (index , typing .Hashable ):
333+ # Python 3.9 doesn't allow isinstance of Optional
301334 index = typing .cast (Optional [str ], index )
302335 block = self ._block .with_column_labels ([index ])
303- return Series (block )
336+
337+ if inplace :
338+ self ._block = block
339+ return None
340+ else :
341+ return Series (block )
304342
305343 raise ValueError (f"Unsupported type of parameter index: { type (index )} " )
306344
307- @validations .requires_index
345+ @overload
346+ def rename_axis (
347+ self ,
348+ mapper : typing .Union [blocks .Label , typing .Sequence [blocks .Label ]],
349+ ) -> Series :
350+ ...
351+
352+ @overload
308353 def rename_axis (
309354 self ,
310355 mapper : typing .Union [blocks .Label , typing .Sequence [blocks .Label ]],
356+ * ,
357+ inplace : Literal [False ],
311358 ** kwargs ,
312359 ) -> Series :
360+ ...
361+
362+ @overload
363+ def rename_axis (
364+ self ,
365+ mapper : typing .Union [blocks .Label , typing .Sequence [blocks .Label ]],
366+ * ,
367+ inplace : Literal [True ],
368+ ** kwargs ,
369+ ) -> None :
370+ ...
371+
372+ @validations .requires_index
373+ def rename_axis (
374+ self ,
375+ mapper : typing .Union [blocks .Label , typing .Sequence [blocks .Label ]],
376+ * ,
377+ inplace : bool = False ,
378+ ** kwargs ,
379+ ) -> Optional [Series ]:
313380 if len (kwargs ) != 0 :
314381 raise NotImplementedError (
315382 f"rename_axis does not currently support any keyword arguments. { constants .FEEDBACK_LINK } "
@@ -319,7 +386,13 @@ def rename_axis(
319386 labels = mapper
320387 else :
321388 labels = [mapper ]
322- return Series (self ._block .with_index_labels (labels ))
389+
390+ block = self ._block .with_index_labels (labels )
391+ if inplace :
392+ self ._block = block
393+ return None
394+ else :
395+ return Series (block )
323396
324397 def equals (
325398 self , other : typing .Union [Series , bigframes .dataframe .DataFrame ]
0 commit comments