6969 NDFrameT ,
7070 RandomState ,
7171 Renamer ,
72+ Scalar ,
7273 SortKind ,
7374 StorageOptions ,
7475 Suffixes ,
@@ -5104,11 +5105,21 @@ def sort_index(
51045105
51055106 @doc (
51065107 klass = _shared_doc_kwargs ["klass" ],
5107- axes = _shared_doc_kwargs ["axes" ],
5108- optional_labels = "" ,
5109- optional_axis = "" ,
5108+ optional_reindex = "" ,
51105109 )
5111- def reindex (self : NDFrameT , * args , ** kwargs ) -> NDFrameT :
5110+ def reindex (
5111+ self : NDFrameT ,
5112+ labels = None ,
5113+ index = None ,
5114+ columns = None ,
5115+ axis : Axis | None = None ,
5116+ method : str | None = None ,
5117+ copy : bool_t | None = None ,
5118+ level : Level | None = None ,
5119+ fill_value : Scalar | None = np .nan ,
5120+ limit : int | None = None ,
5121+ tolerance = None ,
5122+ ) -> NDFrameT :
51125123 """
51135124 Conform {klass} to new index with optional filling logic.
51145125
@@ -5118,11 +5129,7 @@ def reindex(self: NDFrameT, *args, **kwargs) -> NDFrameT:
51185129
51195130 Parameters
51205131 ----------
5121- {optional_labels}
5122- {axes} : array-like, optional
5123- New labels / index to conform to, should be specified using
5124- keywords. Preferably an Index object to avoid duplicating data.
5125- {optional_axis}
5132+ {optional_reindex}
51265133 method : {{None, 'backfill'/'bfill', 'pad'/'ffill', 'nearest'}}
51275134 Method to use for filling holes in reindexed DataFrame.
51285135 Please note: this is only applicable to DataFrames/Series with a
@@ -5311,31 +5318,34 @@ def reindex(self: NDFrameT, *args, **kwargs) -> NDFrameT:
53115318 # TODO: Decide if we care about having different examples for different
53125319 # kinds
53135320
5314- # construct the args
5315- axes , kwargs = self ._construct_axes_from_arguments (args , kwargs )
5316- method = clean_reindex_fill_method (kwargs .pop ("method" , None ))
5317- level = kwargs .pop ("level" , None )
5318- copy = kwargs .pop ("copy" , None )
5319- limit = kwargs .pop ("limit" , None )
5320- tolerance = kwargs .pop ("tolerance" , None )
5321- fill_value = kwargs .pop ("fill_value" , None )
5322-
5323- # Series.reindex doesn't use / need the axis kwarg
5324- # We pop and ignore it here, to make writing Series/Frame generic code
5325- # easier
5326- kwargs .pop ("axis" , None )
5327-
5328- if kwargs :
5329- raise TypeError (
5330- "reindex() got an unexpected keyword "
5331- f'argument "{ list (kwargs .keys ())[0 ]} "'
5332- )
5321+ if index is not None and columns is not None and labels is not None :
5322+ raise TypeError ("Cannot specify all of 'labels', 'index', 'columns'." )
5323+ elif index is not None or columns is not None :
5324+ if axis is not None :
5325+ raise TypeError (
5326+ "Cannot specify both 'axis' and any of 'index' or 'columns'"
5327+ )
5328+ if labels is not None :
5329+ if index is not None :
5330+ columns = labels
5331+ else :
5332+ index = labels
5333+ else :
5334+ if axis and self ._get_axis_number (axis ) == 1 :
5335+ columns = labels
5336+ else :
5337+ index = labels
5338+ axes : dict [Literal ["index" , "columns" ], Any ] = {
5339+ "index" : index ,
5340+ "columns" : columns ,
5341+ }
5342+ method = clean_reindex_fill_method (method )
53335343
53345344 # if all axes that are requested to reindex are equal, then only copy
53355345 # if indicated must have index names equal here as well as values
53365346 if all (
5337- self ._get_axis (axis ).identical (ax )
5338- for axis , ax in axes .items ()
5347+ self ._get_axis (axis_name ).identical (ax )
5348+ for axis_name , ax in axes .items ()
53395349 if ax is not None
53405350 ):
53415351 return self .copy (deep = copy )
@@ -5519,7 +5529,7 @@ def filter(
55195529 name = self ._get_axis_name (axis )
55205530 # error: Keywords must be strings
55215531 return self .reindex ( # type: ignore[misc]
5522- ** {name : [r for r in items if r in labels ]}
5532+ ** {name : [r for r in items if r in labels ]} # type: ignore[arg-type]
55235533 )
55245534 elif like :
55255535
0 commit comments