BUG: Grouped Rolling Var and Std does not work with closed="left" · Issue #42442 · pandas-dev/pandas (original) (raw)


import pandas as pd df = pd.DataFrame([1, 2, 3, 4, 5, 6, 7, 8]) df.groupby([1,2,1,2,1,2,1,2]).rolling(2, closed="left").var(0)

Output: 0 1 0 NaN 2 NaN 4 1.0 6 1.0 2 1 NaN 3 NaN 5 NaN 7 NaN

Problem description

It seems that the rolling variance is only calculated on the first group.

Expected Output

   0

1 0 NaN 2 NaN 4 1.0 6 1.0 2 1 NaN 3 NaN 5 1.0 7 1.0

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f00ed8f
python : 3.7.8.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.3.0
numpy : 1.19.2
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.3
setuptools : 49.6.0.post20201009
Cython : None
pytest : 6.1.1
hypothesis : None
sphinx : 3.2.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.2
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.5.3
sqlalchemy : None
tables : None
tabulate : 0.8.9
xarray : 0.18.2
xlrd : None
xlwt : None
numba : None