BUG: pd.Series.rolling - center=True doesnt work when using numba engine · Issue #34784 · pandas-dev/pandas (original) (raw)
Rolling over a Series with center=True gives different results depending on the engine used:
import pandas as pd test_ser = pd.Series(np.arange(0,10)) rolled_without_numba =test_ser.rolling(3, center=True).apply(lambda x:x[1],raw=True)
rolled_with_numba = test_ser.rolling(3, center=True).apply(lambda x:x[1],raw=True, engine='numba', engine_kwargs={'no_python':True})
Problem description
wheras the result for rolling without the engine is as expected:
rolled_without_numba.head() 0 NaN 1 1.0 2 2.0 3 3.0 4 4.0
rolling with the numba engine gives:
rolled_with_numba.head() 0 NaN 1 NaN 2 1.0 3 2.0 4 3.0
The behavior is problematic at least because its not documented and causes frustrating bug tracing sessions. That the use of numba engine may change the result numerically, is not the first guess.
.
Since rolling with offset is not possible when using numba engine anyway, finding the center labels after rolling is not too big a problem - so maybe instead of a fix, a documentation or a warning would be sufficient.
Expected Output
rolled_with_numba.equals(rolled_without_numba)
Output of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.6.8.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-53-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : de_DE.UTF-8
LOCALE : de_DE.UTF-8
pandas : 1.0.4
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 19.0.3
setuptools : 46.1.3
Cython : 0.29.17
pytest : 5.3.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.2.1
html5lib : 0.999999999
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : 4.6.0
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : 4.2.1
matplotlib : 3.1.3
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.16.0
pytables : None
pytest : 5.3.5
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : 0.8.3
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : 0.48.0