Description
Bug report
Bug description:
When using the built-in dict() constructor on a pandas.DataFrameGroupBy object, Python raises the following error:
TypeError: 'str' object is not callable
This happens despite the following confirmations:
dict is <class 'type'> and not overwritten
df.groupby('security') yields valid (str, DataFrame) pairs
{k: v for k, v in df.groupby(...)} works as expected
dict([('a', 1), ('b', 2)]) works as expected
Error persists even in fresh Poetry virtual environments and minimal isolated scripts
import pandas as pd
df = pd.DataFrame({
'security': ['A', 'B'],
'price': [1, 2]
})
print(dict(df.groupby('security')))
Expected output:
{
'A': pd.DataFrame(...),
'B': pd.DataFrame(...)
}
Actual output:
TypeError: 'str' object is not callable
Item | Value |
---|---|
Python version | 3.12.3 |
OS | Ubuntu 22.04 |
pandas version | 2.3.0 |
Install method | poetry |
Reproduced in venv | Yes |
Reproduced in CLI | Yes |
Additional Notes
- No local or global shadowing of dict
- Running type(dict) returns <class 'type'>
- Running dict is builtins.dict returns True
- Minimal reproduction still fails with same error
- Appears to be interpreter-level misinterpretation of built-in symbol
I’ve run integrity checks, deleted caches, and rebuilt environments—all to no avail. Let me know if I can help isolate it further or dig into Python internals!
CPython versions tested on:
3.12
Operating systems tested on:
Linux