Closed
Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
I have confirmed this bug exists on the master branch of pandas.
Reproducible Example
import numpy as np
import pandas as pd
frame = pd.DataFrame({"a": np.random.randint(0, 5, 50), "b": ["foo", "bar"] * 25})
frame[["b"]].groupby(frame["a"]).mean()
Issue Description
the code sample was raising DataError: No numeric types to aggregate
in 1.2.5 but in 1.3.x this now issues a warning that it will raise in the future. (and also appears that the stacklevel is incorrect)
on master
>>> frame[["b"]].groupby(frame["a"]).mean()
sys:1: FutureWarning: Dropping invalid columns in DataFrameGroupBy.mean is deprecated. In a future version, a TypeError will be raised. Before calling .mean, select only columns which should be valid for the function.
Empty DataFrame
Columns: []
Index: [0, 1, 2, 3, 4]
The change to a empty dataframe was in #41706 with the warning being added in #43154
Expected Behavior
same as 1.2.5
>>> frame[["b"]].groupby(frame["a"]).mean()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/simon/miniconda3/envs/pandas-1.2.5/lib/python3.9/site-packages/pandas/core/groupby/groupby.py", line 1496, in mean
return self._cython_agg_general(
File "/home/simon/miniconda3/envs/pandas-1.2.5/lib/python3.9/site-packages/pandas/core/groupby/generic.py", line 1015, in _cython_agg_general
agg_mgr = self._cython_agg_blocks(
File "/home/simon/miniconda3/envs/pandas-1.2.5/lib/python3.9/site-packages/pandas/core/groupby/generic.py", line 1121, in _cython_agg_blocks
raise DataError("No numeric types to aggregate")
pandas.core.base.DataError: No numeric types to aggregate
Installed Versions
pd.show_versions()