Skip to content

interpolate erroneously fills NaNs at start of series when limit_direction == 'both' #11115

Closed
@lmjohns3

Description

@lmjohns3

PR #10691 had a bug in computing the NaN mask in certain cases.

Specifically, when a NaN occurs within limit of the beginning of the series and limit_direction is set to 'both', the interpolation code will erroneously interpolate these NaNs rather than masking them off.

From the PR:

In [43]: ser = pd.Series([np.nan, np.nan, 5, np.nan, np.nan, np.nan, 13])
In [44]: ser.interpolate(limit=1, limit_direction='both')
Out[44]: 
0     5
1     5
2     5
3     7
4   NaN
5    11
6    13
dtype: float64

This should actually give:

Out[44]: 
0     NaN
1     5
2     5
3     7
4   NaN
5    11
6    13
dtype: float64

Metadata

Metadata

Assignees

No one assigned

    Labels

    Missing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions