-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Type mismatch in read_json #35464
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
Labels
Bug
IO JSON
read_json, to_json, json_normalize
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Comments
I was just running into a semi-related issue... I played around a bit. Weird results: >>> pd.__version__
'1.1.0'
>>> test_json1='{"file_path": null}'
>>> pd.read_json(test_json1, typ='series').to_dict()
{'file_path': NaT}
>>> test_json2='{"file_path": null, "file_size": 0}'
>>> pd.read_json(test_json2, typ='series').to_dict()
{'file_path': nan, 'file_size': 0.0}
>>> test_json3='{"file_path": null, "file_size": null}'
>>> pd.read_json(test_json3, typ='series').to_dict()
{'file_path': NaT, 'file_size': NaT}
>>> test_json4='{"file_path": null, "file_size": ""}'
>>> pd.read_json(test_json4, typ='series').to_dict()
{'file_path': NaT, 'file_size': NaT}
>>> test_json5='{"file_path": null, "file_size": "test"}'
>>> pd.read_json(test_json5, typ='series').to_dict()
{'file_path': None, 'file_size': 'test'}
>>> test_json6='{"file_path": null, "file_size": 0, "file_meta": "hello"}'
>>> pd.read_json(test_json6, typ='series').to_dict()
{'file_path': None, 'file_size': 0, 'file_meta': 'hello'}
#-------------------------
# test_json1='{"file_path": null}'
>>> pd.read_json(test_json1, typ='series')
file_path NaT
dtype: datetime64[ns]
# test_json2='{"file_path": null, "file_size": 0}'
>>> pd.read_json(test_json2, typ='series')
file_path NaN
file_size 0.0
dtype: float64
# test_json4='{"file_path": null, "file_size": ""}'
>>> pd.read_json(test_json4, typ='series')
file_path NaT
file_size NaT
dtype: datetime64[ns]
# test_json6='{"file_path": null, "file_size": 0, "file_meta": "hello"}'
>>> pd.read_json(test_json6, typ='series')
file_path None
file_size 0
file_meta hello
dtype: object So it looks like 3 different scenarios:
|
This was referenced Sep 6, 2023
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
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Tested on Pandas v1.1.0
I'm trying to import a JSON file containing the following:
test.json
If I run the following code,
I get this output:
Why is
null
getting converted toNaT
instead ofNone
?The text was updated successfully, but these errors were encountered: