When using rolling
on a series that contains inf
values the result contains NaN
even if the operation is well defined, like min
or max
. For example:
import numpy as np
import pandas as pd
s = pd.Series([1, 2, 3, np.inf, 5, 6])
print(s.rolling(window=3).min())
This gives:
0 NaN
1 NaN
2 1.0
3 NaN
4 NaN
5 NaN
dtype: float64
while I expected
0 NaN
1 NaN
2 1.0
3 2.0
4 3.0
5 5.0
Computing the minimum of the series directly works as expected:
s.min() # 1.0
What is the reason for additional NaN
values being introduced?
Python 3.8.1, pandas 1.0.2