Skip to content

SeriesGroupBy.transform cannot handle empty series #26208

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
HHest opened this issue Apr 25, 2019 · 4 comments · Fixed by #26228
Closed

SeriesGroupBy.transform cannot handle empty series #26208

HHest opened this issue Apr 25, 2019 · 4 comments · Fixed by #26228
Labels
Milestone

Comments

@HHest
Copy link
Contributor

HHest commented Apr 25, 2019

Code Sample, a copy-pastable example if possible

d = pd.DataFrame({1: [], 2: []})
g = d.groupby(1)
g[2].transform(lambda x: x)

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\python37\lib\site-packages\pandas\core\groupby\generic.py", line 945, in transform
    result = concat(results).sort_index()
  File "C:\python37\lib\site-packages\pandas\core\reshape\concat.py", line 228, in concat
    copy=copy, sort=sort)
  File "C:\python37\lib\site-packages\pandas\core\reshape\concat.py", line 262, in __init__
    raise ValueError('No objects to concatenate')

Problem description

Crashes on SeriesGroupby obj with zero length, which came from an empty dataframe. Would be nicer if pandas can handle this case without raising errors, by for example, just return an empty series. Thanks.

Expected Output

Series([], Name: 2, dtype: float64)

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.7.3.final.0 python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 142 Stepping 9, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None pandas: 0.24.2 pytest: 4.4.1 pip: 19.0.3 setuptools: 41.0.1 Cython: None numpy: 1.15.4 scipy: 1.1.0 pyarrow: None xarray: None IPython: None sphinx: None patsy: 0.5.1 dateutil: 2.7.5 pytz: 2018.7 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: 3.0.2 openpyxl: 2.5.12 xlrd: 1.2.0 xlwt: 1.3.0 xlsxwriter: None lxml.etree: None bs4: None html5lib: None sqlalchemy: None pymysql: None psycopg2: None jinja2: None s3fs: None fastparquet: None pandas_gbq: None pandas_datareader: None gcsfs: None
@WillAyd
Copy link
Member

WillAyd commented Apr 25, 2019

I suppose that would make this consistent with apply and agg:

>>> g[2].apply(lambda x: x)
Series([], Name: 2, dtype: float64)
>>> g[2].agg(lambda x: x)
Series([], Name: 2, dtype: float64)

If you want to take a look and have a simple way of making it work would take a PR

@WillAyd WillAyd added this to the Contributions Welcome milestone Apr 25, 2019
@WillAyd
Copy link
Member

WillAyd commented Apr 25, 2019

Related to #17093

@HHest
Copy link
Contributor Author

HHest commented Apr 26, 2019

Okay, thanks. I see a possible patch. Need to read over contribution guideline and set up a working env to create a PR.

@HHest
Copy link
Contributor Author

HHest commented Apr 27, 2019

The PR I just submitted doesn't fix #17093

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants