-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: AttributeError about dateutil.relativedelta when calling pd.read_json(json_data) #59227
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
Comments
Thanks for the report, can you please provide a copy pastable reproducible example? see - https://matthewrocklin.com/minimal-bug-reports |
imported libraries are: The trigger json_data = {'schema': {'fields': [{'name': 'index', 'type': 'integer'}, {'name': 'Season', 'type': 'string'}, {'name': 'Timeslot_Times_listed_are_Eastern_time', 'type': 'string'}, {'name': 'Season_premiere', 'type': 'string'}, {'name': 'Season_finale', 'type': 'string'}, {'name': 'TV_season', 'type': 'string'}, {'name': 'Ranking', 'type': 'string'}, {'name': 'Viewers_in_millions_of_households', 'type': 'string'}], 'primaryKey': ['index'], 'pandas_version': '1.4.0'}, 'data': [{'index': 0, 'Season': '1st', 'Timeslot_Times_listed_are_Eastern_time': 'Thursday, 10:00 p.m.', 'Season_premiere': 'September 18, 1994', 'Season_finale': 'May 22, 1995', 'TV_season': '1994–1995', 'Ranking': '29', 'Viewers_in_millions_of_households': '11.2'}, {'index': 1, 'Season': '2nd', 'Timeslot_Times_listed_are_Eastern_time': 'Monday 10:00 p.m.', 'Season_premiere': 'September 18, 1995', 'Season_finale': 'May 20, 1996', 'TV_season': '1995–1996', 'Ranking': '24', 'Viewers_in_millions_of_households': '11.4'}, {'index': 2, 'Season': '3rd', 'Timeslot_Times_listed_are_Eastern_time': 'Monday 10:00 p.m.', 'Season_premiere': 'September 16, 1996', 'Season_finale': 'May 19, 1997', 'TV_season': '1996–1997', 'Ranking': '30', 'Viewers_in_millions_of_households': '10.2'}, {'index': 3, 'Season': '4th', 'Timeslot_Times_listed_are_Eastern_time': 'Wednesday 10:00 p.m.', 'Season_premiere': 'October 1, 1997', 'Season_finale': 'May 13, 1998', 'TV_season': '1997–1998', 'Ranking': '39', 'Viewers_in_millions_of_households': '8.9'}, {'index': 4, 'Season': '5th', 'Timeslot_Times_listed_are_Eastern_time': 'Wednesday 10:00 p.m.', 'Season_premiere': 'September 30, 1998', 'Season_finale': 'May 19, 1999', 'TV_season': '1998–1999', 'Ranking': '73', 'Viewers_in_millions_of_households': '9.9'}]} |
But that's okay, I'm trying handling this Also, wish u guys to fix this up in the future.^_^ |
take |
@cspzyy I am a bit confused, what the issue is here, I created the json_data in python code and passed it through to the read_json function. It simply errored out saying it needed a file. Thus had to wrap the string in the StringIO and then there were no issues json_data = {'schema': {'fields': [{'name': 'index', 'type': 'integer'}, {'name': 'Season', 'type': 'string'}, {'name': 'Timeslot_Times_listed_are_Eastern_time', 'type': 'string'}, {'name': 'Season_premiere', 'type': 'string'}, {'name': 'Season_finale', 'type': 'string'}, {'name': 'TV_season', 'type': 'string'}, {'name': 'Ranking', 'type': 'string'}, {'name': 'Viewers_in_millions_of_households', 'type': 'string'}], 'primaryKey': ['index'], 'pandas_version': '1.4.0'}, 'data': [{'index': 0, 'Season': '1st', 'Timeslot_Times_listed_are_Eastern_time': 'Thursday, 10:00 p.m.', 'Season_premiere': 'September 18, 1994', 'Season_finale': 'May 22, 1995', 'TV_season': '1994–1995', 'Ranking': '29', 'Viewers_in_millions_of_households': '11.2'}, {'index': 1, 'Season': '2nd', 'Timeslot_Times_listed_are_Eastern_time': 'Monday 10:00 p.m.', 'Season_premiere': 'September 18, 1995', 'Season_finale': 'May 20, 1996', 'TV_season': '1995–1996', 'Ranking': '24', 'Viewers_in_millions_of_households': '11.4'}, {'index': 2, 'Season': '3rd', 'Timeslot_Times_listed_are_Eastern_time': 'Monday 10:00 p.m.', 'Season_premiere': 'September 16, 1996', 'Season_finale': 'May 19, 1997', 'TV_season': '1996–1997', 'Ranking': '30', 'Viewers_in_millions_of_households': '10.2'}, {'index': 3, 'Season': '4th', 'Timeslot_Times_listed_are_Eastern_time': 'Wednesday 10:00 p.m.', 'Season_premiere': 'October 1, 1997', 'Season_finale': 'May 13, 1998', 'TV_season': '1997–1998', 'Ranking': '39', 'Viewers_in_millions_of_households': '8.9'}, {'index': 4, 'Season': '5th', 'Timeslot_Times_listed_are_Eastern_time': 'Wednesday 10:00 p.m.', 'Season_premiere': 'September 30, 1998', 'Season_finale': 'May 19, 1999', 'TV_season': '1998–1999', 'Ranking': '73', 'Viewers_in_millions_of_households': '9.9'}]}
import pandas as pd
import json
from io import StringIO
df = pd.read_json(StringIO(json.dumps(json_data)), orient='table')
print(df) I am on the latest version in main, maybe this issue has already been fixed? |
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 I used
df.read_json(json_data)
, It calls the functionpandas._libs.tslibs.parsing.dateutil_parse()
in pandas package. The specific path ispython3.8/site-packages/pandas/_libs/tslibs/parsing.pyx:692
. Then AttributeError occurs:AttributeError: type object 'relativedelta' has no attribute 'relativedelta'
Now I'm desperate to process this
json_data
, but with this error I can't work with it correctly. Besides,pandas
has no setup.py in the root directory, so I can't correct and use my custom adjustment.DESPERATE to hear from u!!!! And THANKS so much for paying attention to this!
Expected Behavior
The source code uses
from dateutil.relativedelta import relativedelta
, thus when code in the function saysrelativedelta.relativedelta
, the executor will be confused.I consider if u can try
ret+relativedelta()
? Or anything else will workInstalled Versions
pandas 2.0.3
The text was updated successfully, but these errors were encountered: