interpolate erroneously fills NaNs at start of series when limit_direction == 'both' · Issue #11115 · pandas-dev/pandas (original) (raw)

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