Skip to content

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

Closed
@nrcjea001

Description

@nrcjea001
  • 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

Metadata

Metadata

Assignees

Labels

BugRegressionFunctionality that used to work in a prior pandas versionWindowrolling, ewma, expanding

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions