-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Inconsistent handling of empty windows for rolling mean with min_periods=0 #41053
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
Actually I am getting not NaN for sum.
returns
|
@mroeschke Can you help here? Is NaN correct with min_periods=0? |
Yes, there appears to be a bug here somewhere.
|
Indeed. However this seems to be by design and the behavior looks consistent. What's weird is that the reported bug seems to appear depending on the size of the DataFrame used in the rolling mean methods |
[x ] I have checked that this issue has not already been reported.
[x ] 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.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
Problem description
Pandas rolling mean computation inconsistently treats windows with NaN values only, depending on how far they are in the DataFrame. Here we can see how the values for the windows indexed as 10 and 11 are set to 0 or NaN depending on whether we start the computation starting from the 2nd observation or the 3rd.
Other aggregation functions (like sum) don't seem to suffer from this
This only happens when min_periods is set to 0
This doesn't happen in pandas version 1.0.3
This doesn't happen if non NaN values are set to 1 instead of floating values
This could be linked to another reported issue that I haven't identified after a quick search
Expected Output
The expected output would be for the mean computation to return np.NaN for the indexes 10 and 11 in both cases, consistent with pandas documentation and other aggregation functions behavior
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : f2c8480
python : 3.7.10.final.0
python-bits : 64
OS : Linux
OS-release : 4.15.0-142-generic
Version : #146-Ubuntu SMP Tue Apr 13 01:11:19 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.2.3
numpy : 1.19.2
pytz : 2021.1
dateutil : 2.8.1
pip : 21.0.1
setuptools : 49.6.0.post20210108
Cython : 0.29.22
pytest : 6.2.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.22.0
pandas_datareader: 0.9.0
bs4 : None
bottleneck : None
fsspec : 0.8.7
fastparquet : None
gcsfs : None
matplotlib : 3.3.4
numexpr : None
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.6.2
sqlalchemy : None
tables : None
tabulate : None
xarray : 0.17.0
xlrd : None
xlwt : None
numba : 0.53.1
The text was updated successfully, but these errors were encountered: