-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Mean of zeros turn out to be non-zero #36031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc @mroeschke i can reproduce this on master |
I found this issue is related to C float number print(9007199254740993.0)
# Output: 9007199254740992.0 In your failing test, the float number |
But the weird thing here is that this number does not fall within the last window. I can see why this would affect the correctness of the first window, but why the last? The how is this remainder of -1 transferred across window bounds? Any hyposesis, @aelafifi? |
I suspect this is a numerical precision issue based on how mean is calculated under the hood (the sums are added and removed across the entire dataset instead of the mean being calculated in isolation from the window slice taken) |
Sounds plausible. Any way I can contribute to getting this fixed as someone who just knows the public API of Pandas? |
using kahan summation under the hood would fix this (we do this for var already) PR welcome |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Code Sample, a copy-pastable example
Problem description
In both these cases, the final rolling mean value is the mean of three zeros, but in the
failing_test
, this does not result in a zero value. I am expecting thefailing_test
to have the same behaviour as thesucceeding_test
. The difference lies in the magnitude of the first value in the df, but that shouldn't affect the last mean, as it falls outside the rolling window for that value.Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : f2ca0a2
python : 3.6.9.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-42-generic
Version : #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.1.1
numpy : 1.16.4
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.2
setuptools : 46.1.1
Cython : None
pytest : 4.6.11
hypothesis : 4.57.1
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.4 (dt dec pq3 ext lo64)
jinja2 : 2.11.2
IPython : 7.16.1
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.1
numexpr : 2.7.1
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.1
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : 3.6.1
tabulate : None
xarray : 0.16.0
xlrd : 1.2.0
xlwt : None
numba : 0.47.0
The text was updated successfully, but these errors were encountered: