@@ -6797,106 +6797,6 @@ def interpolate(
67976797 Name: d, dtype: float64
67986798 """
67996799
6800- @doc (_shared_docs ["interpolate" ], ** _shared_doc_kwargs )
6801- def interpolate (
6802- self ,
6803- method = "linear" ,
6804- axis = 0 ,
6805- limit = None ,
6806- inplace = False ,
6807- limit_direction = "forward" ,
6808- limit_area = None ,
6809- downcast = None ,
6810- ** kwargs ,
6811- ):
6812- """
6813- Interpolate values according to different methods.
6814- """
6815- inplace = validate_bool_kwarg (inplace , "inplace" )
6816-
6817- axis = self ._get_axis_number (axis )
6818-
6819- fillna_methods = ["ffill" , "bfill" , "pad" , "backfill" ]
6820- should_transpose = axis == 1 and method not in fillna_methods
6821-
6822- obj = self .T if should_transpose else self
6823-
6824- if method not in fillna_methods :
6825- axis = self ._info_axis_number
6826-
6827- if isinstance (obj .index , MultiIndex ) and method != "linear" :
6828- raise ValueError (
6829- "Only `method=linear` interpolation is supported on MultiIndexes."
6830- )
6831-
6832- # Set `limit_direction` depending on `method`
6833- if limit_direction is None :
6834- limit_direction = (
6835- "backward" if method in ("backfill" , "bfill" ) else "forward"
6836- )
6837- else :
6838- if method in ("pad" , "ffill" ) and limit_direction != "forward" :
6839- raise ValueError (
6840- f"`limit_direction` must be 'forward' for method `{ method } `"
6841- )
6842- if method in ("backfill" , "bfill" ) and limit_direction != "backward" :
6843- raise ValueError (
6844- f"`limit_direction` must be 'backward' for method `{ method } `"
6845- )
6846-
6847- if obj .ndim == 2 and np .all (obj .dtypes == np .dtype (object )):
6848- raise TypeError (
6849- "Cannot interpolate with all object-dtype columns "
6850- "in the DataFrame. Try setting at least one "
6851- "column to a numeric dtype."
6852- )
6853-
6854- # create/use the index
6855- if method == "linear" :
6856- # prior default
6857- index = np .arange (len (obj .index ))
6858- else :
6859- index = obj .index
6860- methods = {"index" , "values" , "nearest" , "time" }
6861- is_numeric_or_datetime = (
6862- is_numeric_dtype (index .dtype )
6863- or is_datetime64_any_dtype (index .dtype )
6864- or is_timedelta64_dtype (index .dtype )
6865- )
6866- if method not in methods and not is_numeric_or_datetime :
6867- raise ValueError (
6868- "Index column must be numeric or datetime type when "
6869- f"using { method } method other than linear. "
6870- "Try setting a numeric or datetime index column before "
6871- "interpolating."
6872- )
6873-
6874- if isna (index ).any ():
6875- raise NotImplementedError (
6876- "Interpolation with NaNs in the index "
6877- "has not been implemented. Try filling "
6878- "those NaNs before interpolating."
6879- )
6880- new_data = obj ._mgr .interpolate (
6881- method = method ,
6882- axis = axis ,
6883- index = index ,
6884- limit = limit ,
6885- limit_direction = limit_direction ,
6886- limit_area = limit_area ,
6887- inplace = inplace ,
6888- downcast = downcast ,
6889- ** kwargs ,
6890- )
6891-
6892- result = self ._constructor (new_data )
6893- if should_transpose :
6894- result = result .T
6895- if inplace :
6896- return self ._update_inplace (result )
6897- else :
6898- return result .__finalize__ (self , method = "interpolate" )
6899-
69006800 # ----------------------------------------------------------------------
69016801 # Timeseries methods Methods
69026802
0 commit comments