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: Groupby rolling count with datetime not working correctly #35869

Closed
2 of 3 tasks
nrcjea001 opened this issue Aug 24, 2020 · 8 comments · Fixed by #36934
Closed
2 of 3 tasks

BUG: Groupby rolling count with datetime not working correctly #35869

nrcjea001 opened this issue Aug 24, 2020 · 8 comments · Fixed by #36934
Assignees
Labels
Bug Regression Functionality that used to work in a prior pandas version Window rolling, ewma, expanding
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

df = pd.DataFrame({"column1": range(6), 
                   "column2": range(6), 
                   'group': 3*['A','B'], 
                   'date':pd.date_range(end="20190101", periods=6)})

## Without Closed Parameter
df.groupby('group').rolling('3d',on='date')['column1'].count()
## Output
group   
A      0    1.0
       2    2.0
       4    3.0
B      1    1.0
       3    2.0
       5    3.0
Name: column1, dtype: float64

## With Closed Parameter
df.groupby('group').rolling('3d',on='date',closed='left')['column1'].count()
## Output
ValueError: closed only implemented for datetimelike and offset based windows

Problem description

In Pandas 1.1.1, although .sum() and .mean() are working correctly, the rolling groupby .count() is not working correctly with datetime. Furthermore, when closed parameter is added, ValueError is produced.

Expected Output

## Without Closed Parameter
group   
A      0    1.0
       2    2.0
       4    2.0
B      1    1.0
       3    2.0
       5    2.0
Name: column1, dtype: float64
## With Closed Parameter
group   
A      0    NaN
       2    1.0
       4    1.0
B      1    NaN
       3    1.0
       5    1.0
Name: column1, dtype: float64

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f2ca0a2
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.1
numpy : 1.18.5
pytz : 2020.1
dateutil : 2.8.1
pip : 20.2.1
setuptools : 49.2.1.post20200802
Cython : 0.29.21
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 : 0.8.0
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 24, 2020
@TomAugspurger
Copy link
Contributor

@nrcjea001 can you check what commit introduced the change, to see if this was deliberate?

@TomAugspurger TomAugspurger added Needs Info Clarification about behavior needed to assess issue Window rolling, ewma, expanding and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 4, 2020
@nrcjea001
Copy link
Author

@TomAugspurger, don't think this was deliberate. If we take the sum and divide by the mean (which is equivalent to the count), we achieve the expected output. However, when using the rolling count function, we do not get the expected output. There has also been some speed improvements to the sum and mean code, while the count is considerably slower (see here). Not sure if this is related.

In regards to the ValueError, the same issue appeared for the mean and sum and was fixed, but not the count (see here).

@TomAugspurger
Copy link
Contributor

TomAugspurger commented Sep 7, 2020 via email

@nrcjea001
Copy link
Author

nrcjea001 commented Sep 8, 2020

Very sorry, I do not have the skill set for this. But thanks for asking

@mroeschke mroeschke removed the Needs Info Clarification about behavior needed to assess issue label Sep 8, 2020
@mroeschke mroeschke self-assigned this Sep 8, 2020
simonjayhawkins added a commit to simonjayhawkins/pandas that referenced this issue Sep 9, 2020
@simonjayhawkins
Copy link
Member

first bad commit: [6875a05] BUG: RollingGroupby with closed and column selection no longer raises ValueError (#35639)

https://github.com/simonjayhawkins/pandas/runs/1092697367?check_suite_focus=true

@simonjayhawkins simonjayhawkins added the Regression Functionality that used to work in a prior pandas version label Sep 9, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1.3 milestone Sep 9, 2020
@simonjayhawkins
Copy link
Member

@mroeschke are you still planning to work on this?

@mroeschke
Copy link
Member

@simonjayhawkins yes but unsure if I'll be able to get to this by 1.1.3. Need to clean up the count code path first to make this easier to debug xref #36649

@simonjayhawkins
Copy link
Member

@simonjayhawkins yes but unsure if I'll be able to get to this by 1.1.3.

not a problem. can move to 1.1.4

@mroeschke Thanks for the update.

@mroeschke mroeschke modified the milestones: 1.1.3, 1.1.4 Sep 26, 2020
@mroeschke mroeschke modified the milestones: 1.1.4, 1.2 Oct 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Regression Functionality that used to work in a prior pandas version Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants