BUG: Segmentation fault in RollingGroupby.mean() with center=True and input with odd length · Issue #35552 · pandas-dev/pandas (original) (raw)


Code Sample, a copy-pastable example

import pandas as pd

series = pd.Series(range(1, 5)) series.groupby(series).rolling(center=True, window=3).mean()

Problem description

With an odd-length series and center=True, RollingGroupby.mean() causes a segfault. If center=True is not provided, or the input series has an even length, then there is no no segfault (example below).

series = pd.Series(range(1, 6)) series.groupby(series).rolling(center=True, window=3).mean()

Outputs:

1  0              NaN
2  1              NaN
3  2              NaN
4  3              NaN
5  4    1.474760e+250
dtype: float64

The series can be grouped in any way, but the example above seemed simplest.

Expected Output

Should output a Series.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : d9fff27
python : 3.7.7.final.0
python-bits : 64
OS : Linux
OS-release : 4.18.0-25-generic
Version : #26-Ubuntu SMP Mon Jun 24 09:32:08 UTC 2019
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.0
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.8.1
pip : 20.1.1
setuptools : 49.2.0.post20200714
Cython : None
pytest : 6.0.1
hypothesis : None
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 : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None