Description
The current documentation for the limit parameter looks like this:
limit : int, default None.
Maximum number of consecutive NaNs to fill.
Several features were not immediately obvious to me and could probably be resolved by slightly better docstring or API design:
-
What happens where the max number of consecutive NaNs is reached? pandas simply stops replacing values, e.g., if there is a gap of 3 values and limit=2, pandas replaces the first 2 values. The alternative would be to entirely ignore gaps of more than 2 values. I'm not saying this would be a better alternative, but we should clarify this.
-
The limit refers to forward filling only, even though interpolation is not inherently directional. It would be nice if there was some way to trigger a limit for back filling at the same time, e.g., with
forward_limit
andbackward_limit
arguments:>>> pd.Series([1, np.nan, np.nan, np.nan, 5]).interpolate(forward_limit=1, backward_limit=1) 0 1 1 2 2 NaN 3 4 4 5 dtype: float64
Thoughts?