BUG: centered rolling on decreasing datetime-index inconsistency · Issue #43927 · pandas-dev/pandas (original) (raw)
- 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 master branch of pandas.
Reproducible Example
import pandas as pd import numpy as np
index = pd.date_range('2020', periods=4, freq='s')
inc = pd.Series([1,1,1,1], index=index).rolling('3s', center=True).sum() dec = pd.Series([1,1,1,1], index=index[::-1]).rolling('3s', center=True).sum()
assert np.all(inc.values == dec.values)
inc 2020-01-01 00:00:00 2.0 2020-01-01 00:00:01 3.0 2020-01-01 00:00:02 3.0 2020-01-01 00:00:03 2.0 Freq: S, dtype: float64
dec 2020-01-01 00:00:03 NaN 2020-01-01 00:00:02 3.0 2020-01-01 00:00:01 3.0 2020-01-01 00:00:00 2.0 Freq: -1S, dtype: float64
Issue Description
the first value is a NaN
when rolling over a decreasing index with center=True
, but it shouldnt. This happens for ever value of closed
.
AFAIK, this comes from the cython implementation of calculate_valiable_window_bounds
.
I prepared a MR for this.
Expected Behavior
no NaN
as first value.
Installed Versions
INSTALLED VERSIONS
commit : 73c6825
python : 3.9.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-88-generic
Version : #99-Ubuntu SMP Thu Sep 23 17:29:00 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.3.3
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 57.0.0
Cython : None
pytest : 6.2.5
hypothesis : 6.17.4
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 4.0.1
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.54.0