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: .to_json() of periode_range gives OverflowError: Maximum recursion level reached #55490

Open
3 tasks done
IbHansen opened this issue Oct 11, 2023 · 4 comments
Open
3 tasks done
Assignees
Labels
Bug IO JSON read_json, to_json, json_normalize Period Period data type

Comments

@IbHansen
Copy link

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>
@IbHansen IbHansen added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 11, 2023
@lithomas1
Copy link
Member

Hi and thanks for reporting this issue, I can confirm that this issue still exists on main.

This might be a duplicate of #31917, even though the error message has changed a bit.

@lithomas1 lithomas1 added IO JSON read_json, to_json, json_normalize Period Period data type and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 12, 2023
@xiaohuanlin
Copy link
Contributor

take

@xiaohuanlin
Copy link
Contributor

I investigated this error and found it was introduced by this PR: #23915
The root cause is it's the new object with the same class when iterating the attributes of a object. In this issue, the special attribute is base and will return the same offset object with a base attribute.
I wonder if I can change the name of this attribute from base to _base. It will prevent iterating this attribute.

@Aloqeely
Copy link
Member

Aloqeely commented Apr 7, 2024

I can still reproduce this on main, this error is really misleading.
If this is not going to be fixed anytime soon we should at least consider raising a TypeError instead

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 Period Period data type
Projects
None yet
Development

No branches or pull requests

4 participants