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

Misleading error messages when opening inexistent json file #29102

Closed
datapythonista opened this issue Oct 19, 2019 · 14 comments · Fixed by #46718
Closed

Misleading error messages when opening inexistent json file #29102

datapythonista opened this issue Oct 19, 2019 · 14 comments · Fixed by #46718
Assignees
Labels
Enhancement Error Reporting Incorrect or improved errors from pandas good first issue IO JSON read_json, to_json, json_normalize

Comments

@datapythonista
Copy link
Member

When opening a json file that doesn't exist with read_json, we get a ValueError with error messages like:

>>> import pandas
>>> pandas.read_json('no_file.json')
ValueError: Unexpected character found when decoding 'null'

>>> pandas.read_json('a_dir/no_file.json')
ValueError: Expected object or value

It'd probably be better to raise an exception like:

FileNotFoundError: No such file: 'no_file.json'
@datapythonista datapythonista added Error Reporting Incorrect or improved errors from pandas IO JSON read_json, to_json, json_normalize Effort Low good first issue labels Oct 19, 2019
@mohitanand001
Copy link
Contributor

Hi, @datapythonista can I take this up?

@datapythonista
Copy link
Member Author

sure, thanks

@deepandas11
Copy link

Hi! Would like to work on this if it is still open.

@sathyz
Copy link
Contributor

sathyz commented Mar 12, 2020

take

@kevin-meyers
Copy link

Hey @sathyz if you don't finish it by the end of the month I think I'll give it a shot.

@devjeetr
Copy link
Contributor

take

@vampypandya
Copy link
Contributor

vampypandya commented May 23, 2020

@devjeetr Is this issue still open? Can I give a shot?

@cheungje
Copy link

Hi, I would like to to take this issue if it's still not resolved.

@cheungje
Copy link

take

@mohitanand001
Copy link
Contributor

Anyone willing to take this up might want to go through this thread once.
#29104
I had taken this 2 years back, but it was closed after some discussion.

@janosh
Copy link
Contributor

janosh commented Apr 8, 2022

Would a PR for this still be welcomed? Reading #29104 makes it sounds like the conclusion there was no good solution exists but tbh I don't understand why not.

@MarcoGorelli
Copy link
Member

If I've understood the discussion correctly, then I think that at least for extensioned json files, it should be possible to assume user intent and raise an informative error message if the file doesn't exist

@janosh
Copy link
Contributor

janosh commented Apr 8, 2022

@MarcoGorelli So if I submit a PR that raises FNFError

if (
    isinstance(filepath_or_buffer, str)
    and filepath_or_buffer.lower().endswith(('.json', '.json.gz', '.json.bz2'))
    and not isfile(filepath_or_buffer)
)

that would be acceptable? Seems like a definite improvement over current behavior to me.

@MarcoGorelli
Copy link
Member

TBH that would look good to me, I often run into this error when trying to read json files - cc @gfyoung @WillAyd any further thoughts on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment