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: DataFrameGroupBy.rolling on an empty DataFrame throws a ValueError #36197

Closed
3 tasks done
rbu opened this issue Sep 7, 2020 · 1 comment · Fixed by #36208
Closed
3 tasks done

BUG: DataFrameGroupBy.rolling on an empty DataFrame throws a ValueError #36197

rbu opened this issue Sep 7, 2020 · 1 comment · Fixed by #36208
Assignees
Labels
Bug Groupby Window rolling, ewma, expanding
Milestone

Comments

@rbu
Copy link

rbu commented Sep 7, 2020

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


Code Sample, a copy-pastable example

import pandas as pd
pd.DataFrame({"s1": []}).groupby("s1").rolling(window=1).sum()

Problem description

Since a pandas update, the groupby above started failing in the edge case of an empty DataFrame. It used to simply return an empty DataFrame before, which seems like a more robust behaviour to me.

Expected Output

>>> pd.DataFrame({"s1": []}).groupby("s1").rolling(window=1).sum()
Empty DataFrame
Columns: []
Index: []

Actual Output

>>> pd.DataFrame({"s1": []}).groupby("s1").rolling(window=1).sum()'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "site-packages/pandas/core/window/rolling.py", line 2072, in sum
    return super().sum(*args, **kwargs)
  File "site-packages/pandas/core/window/rolling.py", line 1424, in sum
    window_func, center=self.center, floor=0, name="sum", **kwargs
  File "site-packages/pandas/core/window/rolling.py", line 2194, in _apply
    **kwargs,
  File "site-packages/pandas/core/window/rolling.py", line 528, in _apply
    blocks, obj = self._create_blocks(self._selected_obj)
  File "site-packages/pandas/core/window/rolling.py", line 2230, in _create_blocks
    list(self._groupby.grouper.indices.values())
  File "<__array_function__ internals>", line 6, in concatenate
ValueError: need at least one array to concatenate

Output of pd.show_versions()

INSTALLED VERSIONS

commit : f2ca0a2
python : 3.7.9.final.0
python-bits : 64
OS : Linux
OS-release : 5.7.17-200.fc32.x86_64
Version : #1 SMP Fri Aug 21 15:23:46 UTC 2020
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.1.1
numpy : 1.19.1
pytz : 2020.1
dateutil : 2.7.3
pip : 19.3.1
setuptools : 42.0.2
Cython : None
pytest : 5.1.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.3.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.10.1
IPython : 7.3.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.0
fastparquet : None
gcsfs : None
matplotlib : 3.0.3
numexpr : None
odfpy : None
openpyxl : 3.0.4
pandas_gbq : None
pyarrow : 0.12.1
pytables : None
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
numba : None

@rbu rbu added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Sep 7, 2020
@mroeschke mroeschke added Groupby Window rolling, ewma, expanding labels Sep 7, 2020
@mroeschke mroeschke self-assigned this Sep 7, 2020
@mroeschke mroeschke removed the Needs Triage Issue that has not been reviewed by a pandas team member label Sep 7, 2020
@rbu
Copy link
Author

rbu commented Sep 7, 2020

The last version where this worked was 1.0.5, i.e. it is broken since 1.1.0rc0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Groupby Window rolling, ewma, expanding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants