original) (raw)
SeriesGroupBy.transform cannot handle empty series · Issue #26208 · pandas-dev/pandas (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 "", line 1, in 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)
pd.show_versions()
Output of 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