Skip to content
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

BUG: skipna keyword no longer accepted by rolling().sum() #55272

Closed
2 of 3 tasks
LeoLi2002 opened this issue Sep 25, 2023 · 3 comments
Closed
2 of 3 tasks

BUG: skipna keyword no longer accepted by rolling().sum() #55272

LeoLi2002 opened this issue Sep 25, 2023 · 3 comments
Labels
Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Usage Question Window rolling, ewma, expanding

Comments

@LeoLi2002
Copy link

LeoLi2002 commented Sep 25, 2023

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd
import numpy as np
a = pd.Series([1,2,3,4,5,6])
a.iloc[3] = np.nan
print(a.rolling(2).sum(skipna=True))

Issue Description

At precvious version, the rolling.sum can use the keyword skipna to exclude nan when calculating, but in this version the parameter have benn removed and the funcation can not work even use .apply(np.nansum)

Expected Behavior

import pandas as pd
import numpya as np
a = pd.Series([1,2,3,4,5,6])
a.iloc[3] = np.nan
print(a.rolling(2).sum(skipna=True))

Installed Versions

pandas : 2.1.0
numpy : 1.25.2
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.0
pip : 23.2.1
Cython : 3.0.2
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : None
pandas_datareader : None
bs4 : None
bottleneck : None
dataframe-api-compat: None
fastparquet : 2023.8.0
fsspec : 2023.9.2
gcsfs : None
matplotlib : 3.8.0
numba : None
numexpr : 2.8.6
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 13.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.2
sqlalchemy : None
tables : 3.8.0
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None

@LeoLi2002 LeoLi2002 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 25, 2023
@rhshadrach
Copy link
Member

Thanks for the report. Can you give this issue an informative title; it is currently BUG:.

In what version of pandas could you specify skipna?

@rhshadrach rhshadrach added Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Window rolling, ewma, expanding Needs Info Clarification about behavior needed to assess issue labels Sep 25, 2023
@jorisvandenbossche jorisvandenbossche changed the title BUG: BUG: skipna keyword no longer accepted by rolling().sum() Oct 27, 2023
@jorisvandenbossche
Copy link
Member

In what version of pandas could you specify skipna?

This "worked" in pandas 1.x, but we were giving a deprecation warning. Running the above snippet with pandas 1.5:

In [5]: print(a.rolling(2).sum(skipna=True))
<ipython-input-5-e7a76e200cf6>:1: FutureWarning: Passing additional kwargs to Rolling.sum has no impact on the result and is deprecated. This will raise a TypeError in a future version of pandas.
  print(a.rolling(2).sum(skipna=True))
0     NaN
1     3.0
2     5.0
3     NaN
4     NaN
5    11.0
dtype: float64

Note that also then this keyword didn't have any affect, AFAIK, and the default is also True, so no need to specify skipna=True.

The reason you get NaNs in the result is because of min_periods (minimum of valid (non-NaN) values present in the window) defaulting to the window size. If you reduce that, you get no NaNs:

In [9]: a.rolling(2, min_periods=0).sum()
Out[9]: 
0     1.0
1     3.0
2     5.0
3     3.0
4     5.0
5    11.0
dtype: float64

@jorisvandenbossche jorisvandenbossche added Usage Question and removed Bug Needs Info Clarification about behavior needed to assess issue Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 27, 2023
@rhshadrach
Copy link
Member

Thanks @jorisvandenbossche. I think this is resolved then. @LeoLi2002 - if you think anything was missed please comment here and we can reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate Usage Question Window rolling, ewma, expanding
Projects
None yet
Development

No branches or pull requests

3 participants