Skip to content

BUG: Groupby dropna=False argument unexpected behaviour with rolling window #35542

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

Closed
2 of 3 tasks
nrcjea001 opened this issue Aug 4, 2020 · 2 comments · Fixed by #36842
Closed
2 of 3 tasks

BUG: Groupby dropna=False argument unexpected behaviour with rolling window #35542

nrcjea001 opened this issue Aug 4, 2020 · 2 comments · Fixed by #36842
Labels
Bug Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@nrcjea001
Copy link

  • 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.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

# Your code here
data = {'group':['g1', 'g1', 'g1', np.nan, 'g1', 'g1', 'g2', 'g2', 'g2', 'g2', np.nan], 
                    'A':[3, 1, 8, 2, 6, -1, 0, 13, -4, 0, 1], 
                    'B':[5, 2, 3, 7, 11, -1, 4,-1, 1, 0, 2]} 
df = pd.DataFrame(data)
df.groupby('group',dropna=False)['A'].rolling(1,min_periods=1).mean()

#### Output
group   
g1     0     3.0
       1     1.0
       2     8.0
       4     6.0
       5    -1.0
g2     6     0.0
       7    13.0
       8    -4.0
       9     0.0
Name: A, dtype: float64

Problem description

In Pandas 1.1.0, dropna=False is introduced as argument in groupby to allow for NA in group keys. However, we do not see this behaviour with rolling groupby. NA is not added to group key.

Expected Output

Nan group key

Output of pd.show_versions()

INSTALLED VERSIONS

commit : d9fff27
python : 3.8.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 11, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United States.1252

pandas : 1.1.0
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.1
setuptools : 49.2.1.post20200802
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.17.0
pandas_datareader: None
bs4 : 4.9.1
bottleneck : None
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.3.0
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.0
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.48.0

@nrcjea001 nrcjea001 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 4, 2020
@erfannariman
Copy link
Member

erfannariman commented Aug 4, 2020

Expected output:

group    
NaN    3      2.0
       10     1.0
g1     0      3.0
       1      1.0
       2      8.0
       4      6.0
       5     -1.0
g2     6      0.0
       7     13.0
       8     -4.0
       9      0.0
Name: A, dtype: float64

@simonjayhawkins simonjayhawkins added this to the Contributions Welcome milestone Aug 15, 2020
@simonjayhawkins simonjayhawkins added Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 15, 2020
@anmolprogrammer123
Copy link

Expected output:

group    
NaN    3      2.0
       10     1.0
g1     0      3.0
       1      1.0
       2      8.0
       4      6.0
       5     -1.0
g2     6      0.0
       7     13.0
       8     -4.0
       9      0.0
Name: A, dtype: float64

hi, @erfannariman , I want to solve this issue, can I take this issue. I am a beginner in open source and I want to contribute, so it will be great help if you provide some insights about this.

@jreback jreback modified the milestones: Contributions Welcome, 1.2 Oct 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants