Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: DataFrame.dtypes.to_json OverflowError: Maximum recursion level reached #61170

Open
3 tasks done
Aliebc opened this issue Mar 23, 2025 · 2 comments · May be fixed by #61171
Open
3 tasks done

BUG: DataFrame.dtypes.to_json OverflowError: Maximum recursion level reached #61170

Aliebc opened this issue Mar 23, 2025 · 2 comments · May be fixed by #61171
Assignees
Labels
Bug IO JSON read_json, to_json, json_normalize

Comments

@Aliebc
Copy link
Contributor

Aliebc commented Mar 23, 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

import pandas as pd
from io import StringIO

df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})

dts = df.dtypes
print(dts)

# dts to csv
# Expected: A,int64\nB,int64\n No error
test_csv = StringIO()
dts.to_csv(test_csv)
print(test_csv.getvalue())

# dts to json
# Expected: {"A": "int64", "B": "int64"} No error
print(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

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

@Aliebc Aliebc added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 23, 2025
@snitish
Copy link
Member

snitish commented Mar 24, 2025

Confirmed on main

@snitish snitish added IO JSON read_json, to_json, json_normalize and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 24, 2025
@Aliebc 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
@GalkaKG
Copy link

GalkaKG commented Mar 24, 2025

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants