Pandas version checks

  • [X] I have checked that this issue has not already been reported.

  • [X] 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
import json

df = pd.read_json(json.dumps(json_data), orient='table')

Issue Description

When I used df.read_json(json_data), It calls the function pandas._libs.tslibs.parsing.dateutil_parse() in pandas package. The specific path is python3.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 says relativedelta.relativedelta, the executor will be confused.

I consider if u can try ret+relativedelta()? Or anything else will work

Installed Versions

pandas 2.0.3

Comment From: asishm

Thanks for the report, can you please provide a copy pastable reproducible example? see - https://matthewrocklin.com/minimal-bug-reports

Comment From: cspzyy

Thanks for the report, can you please provide a copy pastable reproducible example? see - https://matthewrocklin.com/minimal-bug-reports

imported libraries are: import pandas as pd import json

The trigger json_data is as following, and I write df = pd.read_json(json.dumps(json_data), orient='table') for the data. Then the AttributeError occured. Please check it, thanks a lot!

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'}]}

Comment From: cspzyy

But that's okay, I'm trying handling this json_data with raw python code. Thanks for your attention again!

Also, wish u guys to fix this up in the future.^_^

Comment From: ritwizsinha

take

Comment From: ritwizsinha

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