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
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