Description
Pandas version checks
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
df = pd.DataFrame(index=pd.date_range(start="2024-02-01", end="2024-02-21", freq="1d"))
df["A"] = df.index.day.astype(float)
df.iloc[-2, 0] = np.inf
df.iloc[-9, 0] = np.nan
res1 = df.rolling(window=pd.Timedelta("4d")).mean()
res2 = df.rolling(window=4).mean()
Issue Description
When passing a timedelta to the rolling method, entries like nan and inf are being ignored. Also missing values at the beginning of the column are not taken into account for the calculation. In the Reproducible Example both results res1 and res2 should be equal, but they are not.
Expected Behavior
Missing and invalid values should be taken into account properly when passing a TimeDelta.
Installed Versions
INSTALLED VERSIONS
commit : f538741
python : 3.10.2.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : AMD64 Family 25 Model 80 Stepping 0, AuthenticAMD
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 2.2.0
numpy : 1.26.4
pytz : 2024.1
dateutil : 2.8.2
setuptools : 58.1.0
pip : 21.2.4
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 8.21.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.8.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 15.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.12.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.4
qtpy : None
pyqt5 : None