CLN: enforce deprecation of NDFrame.interpolate with ffill/bfill/pad/backfill methods by natmokval · Pull Request #57869 · pandas-dev/pandas (original) (raw)
Just to be clear, here's the diff of the change I think you can fully clean up (I think we don't need any logic dealing with checking for a fillna_method):
--- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -7797,30 +7797,11 @@ class NDFrame(PandasObject, indexing.IndexingMixin): if not isinstance(method, str): raise ValueError("'method' should be a string, not None.") - fillna_methods = ["ffill", "bfill", "pad", "backfill"] - if method.lower() in fillna_methods: - # GH#53581 - warnings.warn( - f"{type(self).name}.interpolate with method={method} is " - "deprecated and will raise in a future version. " - "Use obj.ffill() or obj.bfill() instead.", - FutureWarning, - stacklevel=find_stack_level(), - ) - obj, should_transpose = self, False - else: - obj, should_transpose = (self.T, True) if axis == 1 else (self, False) - f"{type(self).name} cannot interpolate with object dtype." - )
if method in fillna_methods and "fill_value" in kwargs:raise ValueError("'fill_value' is not a valid keyword for "f"{type(self).__name__}.interpolate with method from "f"{fillna_methods}"
obj, should_transpose = (self.T, True) if axis == 1 else (self, False)# GH#53631if np.any(obj.dtypes == object):raise TypeError(f"{type(self).__name__} cannot interpolate with object dtype." ) if isinstance(obj.index, MultiIndex) and method != "linear":
@@ -7830,34 +7811,16 @@ class NDFrame(PandasObject, indexing.IndexingMixin): limit_direction = missing.infer_limit_direction(limit_direction, method) - if method.lower() in fillna_methods: - # TODO(3.0): remove this case - # TODO: warn/raise on limit_direction or kwargs which are ignored? - # as of 2023-06-26 no tests get here with either - if not self._mgr.is_single_block and axis == 1: - # GH#53898 - if inplace: - raise NotImplementedError() - obj, axis, should_transpose = self.T, 1 - axis, True
new_data = obj._mgr.pad_or_backfill(method=method,axis=self._get_block_manager_axis(axis),limit=limit,limit_area=limit_area,inplace=inplace,)else:index = missing.get_interp_index(method, obj.index)new_data = obj._mgr.interpolate(method=method,index=index,limit=limit,limit_direction=limit_direction,limit_area=limit_area,inplace=inplace,**kwargs,)
index = missing.get_interp_index(method, obj.index)new_data = obj._mgr.interpolate(method=method,index=index,limit=limit,limit_direction=limit_direction,limit_area=limit_area,inplace=inplace,**kwargs,)