Skip to content

DOC/API: limit argument to interpolate is somewhat non-intuitive #9218

Closed
@shoyer

Description

@shoyer

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:

  1. 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.

  2. 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 and backward_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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions