Description
Pandas version checks
-
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 main branch of pandas.
Reproducible Example
# obj: pandas.core.groupby.generic.DataFrameGroupBy
# in this case we are creating an empty dataframe but it is also reproducible if there are elements in it
obj = pd.DataFrame.from_records([], columns=["foo", "bar", "baz"]).groupby("foo")
x = {k:v for k,v in obj} # works, returns `{}`
y = dict(obj) # raises an exception with `TypeError: attribute of type 'str' is not callable`
Issue Description
Calling dict() on the groupby iterable does not seem to work. This form is considered better by some, see e.g. the flake8/ruff C416 rule which can be automatically applied (this is how I discovered the bug/problem).
I'm not completely sure if this is a problem with pandas or a limitation with how python's dict() method works, but I thought I'd start by filing here.
Expected Behavior
Calling the dict() function should be equivalent to the {k:v for k,v in obj}
form.
Installed Versions
INSTALLED VERSIONS
commit : 37ea63d
python : 3.8.11.final.0
python-bits : 64
OS : Darwin
OS-release : 22.4.0
Version : Darwin Kernel Version 22.4.0: Mon Mar 6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_CA.UTF-8
LOCALE : en_CA.UTF-8
pandas : 2.0.1
numpy : 1.24.3
pytz : 2023.3
dateutil : 2.8.2
setuptools : 56.0.0
pip : 21.1.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None