Open
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
pd.Series(pd.period_range(start=2021,freq = 'Y',periods=3)).to_json()
### Issue Description
causes a: OverflowError: Maximum recursion level reached
the same goes if a periode_range is a column in a dataframe
### Expected Behavior
should return:
'{"0":{"day":31,"day_of_week":4,"day_of_year":365,"dayofweek":4,"dayofyear":365,"days_in_month":31,"daysinmonth":31,"end_time":1640995199999,"freqstr":"A-DEC","hour":0,"is_leap_year":false,"minute":0,"month":12,"ordinal":51,"quarter":4,"qyear":2021,"second":0,"start_time":1609459200000,"week":52,"weekday":4,"weekofyear":52,"year":2021},"1":{"day":31,"day_of_week":5,"day_of_year":365,"dayofweek":5,"dayofyear":365,"days_in_month":31,"daysinmonth":31,"end_time":1672531199999,"freqstr":"A-DEC","hour":0,"is_leap_year":false,"minute":0,"month":12,"ordinal":52,"quarter":4,"qyear":2022,"second":0,"start_time":1640995200000,"week":52,"weekday":5,"weekofyear":52,"year":2022},"2":{"day":31,"day_of_week":6,"day_of_year":365,"dayofweek":6,"dayofyear":365,"days_in_month":31,"daysinmonth":31,"end_time":1704067199999,"freqstr":"A-DEC","hour":0,"is_leap_year":false,"minute":0,"month":12,"ordinal":53,"quarter":4,"qyear":2023,"second":0,"start_time":1672531200000,"week":52,"weekday":6,"weekofyear":52,"year":2023}}'
### Installed Versions
<details>
INSTALLED VERSIONS
------------------
commit : e86ed377639948c64c429059127bcf5b359ab6be
python : 3.10.12.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22621
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Danish_Denmark.1252
pandas : 2.1.1
numpy : 1.26.0
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.2.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 : 3.1.2
IPython : 8.16.1
pandas_datareader : None
bs4 : 4.12.2
bottleneck : None
dataframe-api-compat: 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
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
</details>