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: All arrays must be of the same length fatal error using pd.read_json() #58297

Closed
3 tasks done
kuhlaid opened this issue Apr 17, 2024 · 5 comments
Closed
3 tasks done
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@kuhlaid
Copy link

kuhlaid commented Apr 17, 2024

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

df = pd.read_json('https://gist.githubusercontent.com/kuhlaid/83da2d0511d57b9a697748837436b93d/raw/9260fd3eb0a6d4a3594350d8d584ab27e52fd3c9/data.json')

print(df)
print("finished")

Issue Description

For some reason pd.read_json() balks at the valid JSON at https://gist.githubusercontent.com/kuhlaid/83da2d0511d57b9a697748837436b93d/raw/9260fd3eb0a6d4a3594350d8d584ab27e52fd3c9/data.json with an All arrays must be of the same length fatal error.

Expected Behavior

Would expect pd.read_json() to read valid JSON object.

Installed Versions

INSTALLED VERSIONS

commit : d9cdd2e
python : 3.11.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.146.1-microsoft-standard-WSL2
Version : #1 SMP Thu Jan 11 04:09:03 UTC 2024
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : en_US.UTF-8
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.2.2
numpy : 1.24.4
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.2.2
pip : 23.3
Cython : 3.0.4
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : 1.4.6
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.16.1
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.2
bottleneck : 1.3.7
dataframe-api-compat : None
fastparquet : None
fsspec : 2023.9.2
gcsfs : None
matplotlib : 3.8.0
numba : 0.57.1
numexpr : 2.8.7
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
pyarrow : 13.0.0
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.11.3
sqlalchemy : 2.0.22
tables : 3.9.1
tabulate : None
xarray : None
xlrd : 2.0.1
zstandard : 0.21.0
tzdata : 2023.3
qtpy : None
pyqt5 : None

@kuhlaid kuhlaid added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 17, 2024
@Aloqeely
Copy link
Contributor

Aloqeely commented Apr 18, 2024

Thanks for your report! It will be hard to guess what is causing the error since that JSON file is not small.
Could you provide a simpler JSON file that reproduces the error and show why it is a valid JSON object to pass to pd.read_json?

@kuhlaid
Copy link
Author

kuhlaid commented Apr 19, 2024

This is a shorter version of the JSON than what I am trying to use. I'm not aware of any different versions or exceptions for JSON validation. I'm only using a validator such as https://jsonlint.com/.

@Aloqeely
Copy link
Contributor

Ah, I see.
Your file is in fact a valid JSON file, but I was talking about whether it is appropriate to pass it to a DataFrame.
Maybe you want to parse it to a dictionary instead? You can do that using the json module.

@kuhlaid
Copy link
Author

kuhlaid commented Apr 19, 2024

This is more of a documentation issue than anything or maybe changing the error text is more appropriate. Maybe saying All arrays must be of the same length. Check that your JSON is appropriately organized for conversion to a Dataframe. In other words, the documentation seems to suggest that the read_json function will process any JSON, which it is not meant to do.

@kuhlaid
Copy link
Author

kuhlaid commented Apr 19, 2024

Just consider changing the documentation to note the appropriate JSON organization for Dataframes since the organization of the JSON matters. :)

@kuhlaid kuhlaid closed this as not planned Won't fix, can't repro, duplicate, stale Apr 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

2 participants