You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
importpandasaspdfromioimportStringIOdf=pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
dts=df.dtypesprint(dts)
# dts to csv# Expected: A,int64\nB,int64\n No errortest_csv=StringIO()
dts.to_csv(test_csv)
print(test_csv.getvalue())
# dts to json# Expected: {"A": "int64", "B": "int64"} No errorprint(dts.to_json())
# OverflowError: Maximum recursion level reached
Issue Description
When calling to_csv() on a pd.Series of dtypes, it works without error and outputs as expected. However, calling to_json() on the same Series raises an OverflowError: Maximum recursion level reached.
Expected Behavior
Expected: {"A": "int64", "B": "int64"} without error
Installed Versions
INSTALLED VERSIONS
commit : d9cdd2e
python : 3.11.11.final.0
python-bits : 64
OS : Darwin
OS-release : 24.3.0
Version : Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : zh_CN.UTF-8
LOCALE : zh_CN.UTF-8
Aliebc
changed the title
BUG: DataFrame.to_json OverflowError: Maximum recursion level reached
BUG: DataFrame.dtypes.to_json OverflowError: Maximum recursion level reached
Mar 24, 2025
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
Issue Description
When calling
to_csv()
on apd.Series
ofdtypes
, it works without error and outputs as expected. However, callingto_json()
on the sameSeries
raises anOverflowError: Maximum recursion level reached
.Expected Behavior
Expected: {"A": "int64", "B": "int64"} without error
Installed Versions
INSTALLED VERSIONS
commit : d9cdd2e
python : 3.11.11.final.0
python-bits : 64
OS : Darwin
OS-release : 24.3.0
Version : Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:23 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6020
machine : arm64
processor : arm
byteorder : little
LC_ALL : None
LANG : zh_CN.UTF-8
LOCALE : zh_CN.UTF-8
pandas : 2.2.2
numpy : 1.26.4
pytz : 2022.6
dateutil : 2.8.2
setuptools : 75.6.0
pip : 24.3.1
Cython : None
pytest : 8.2.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.3
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.11.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.12.2
gcsfs : None
matplotlib : 3.8.3
numba : 0.58.1
numexpr : None
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 14.0.1
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.12.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: