Closed batterseapower closed 1 year ago
Thanks for the report - agreed and confirmed on master. Further investigations and a PR to fix is most welcome.
SeriesGroupBy._wrap_applied_output
is used here to create the resulting object
https://github.com/pandas-dev/pandas/blob/860ff03ee1e4de8a1af1cf55e844f38d7876253a/pandas/core/groupby/groupby.py#L1304-L1306
However, if the initial dataframe is empty, then there is no group keys
and _wrap_applied_output
just returns an empty Series
https://github.com/pandas-dev/pandas/blob/860ff03ee1e4de8a1af1cf55e844f38d7876253a/pandas/core/groupby/generic.py#L444-L451
Looks like we have several incorrect tests in tests.resample.test_base testing for the wrong behavior here
Code Sample, a copy-pastable example
Problem description
It is surprising that
groupby.ohlc
returns different data types depending on whether or not there are zero rows.Expected Output
I think it would be more sensible for the zero row case to return a
DataFrame
with columns open/high/low/close, but with zero rows. Returning aSeries
as a special case doesn't make sense.Output of
pd.show_versions()
(This failed with an error about llvmlite.dll in the environment with pandas 1.3.1 installed, so this output is actually from a slightly earlier install of Pandas which still exhibits the bug.)