-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: json that could be read by pandas 1.5.3 cannot be read by 2.0.0 #52595
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
can confirm, thanks @rikardn for the report |
|
Looks like the data as stored is timezone-aware, e.g. "2022-09-12T11:42:33.330Z". so i guess we need convert_json_field_to_pandas_type to return "datetime64[ns, UTC]" instead of "datetime64[ns]" here? or maybe just have it call to_datetime instead of doing an astype? |
cc @WillAyd do you think the to_datetime approach would work? |
The function you mentioned seems like it already should be working with tz-aware objects? pandas/pandas/io/json/_table_schema.py Line 206 in 910f159
|
in this case the user doesn't have |
Hey all, how do you recommend to patch this regression in the meantime? I'd rather not pin to a previous pandas version, but not sure if it's straightforward to make the necessary fix in our code either. It's not a key functionality for prophet but the continuous deployment pipeline does rely on all tests passing. |
cc @WillAyd im hoping you have a bright idea here |
I don't see anything in the JSON table specification for timezone handling, so guessing the |
I sailed around this by doing a rather hacky find-replace |
I'm surprised there isn't a cleaner workaround here or a new flag provided in pandas to fix this. I'm using pandas 2.2.1 So, here's a quick code-fix I used to remove the timezone tags:
|
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
I have serialized a pandas DataFrame into json using pandas 1.4.0. The dataframe contains a
datetime
column. Using pandas 1.5.3 this could be read in fine, but pandas 2.0.0 gives an error (see below) when trying to read it.The problem is that pandas tries to change the datatype of the datetime column at
_table_schema.py:370
ending up with the timezone error.Expected Behavior
I expect it to still be possible to read the json using pandas 2.0.0
Installed Versions
I got an error when running
pd.show_versions()
tests/tools/test_run.py:173: in test_retrieve_models
pd.show_versions()
.tox/py311/lib/python3.11/site-packages/pandas/util/_print_versions.py:109: in show_versions
deps = _get_dependency_info()
.tox/py311/lib/python3.11/site-packages/pandas/util/_print_versions.py:88: in _get_dependency_info
mod = import_optional_dependency(modname, errors="ignore")
.tox/py311/lib/python3.11/site-packages/pandas/compat/_optional.py:142: in import_optional_dependency
module = importlib.import_module(name)
/usr/local/lib/python3.11/importlib/init.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
:1206: in _gcd_import
???
:1178: in _find_and_load
???
:1140: in _find_and_load_unlocked
???
:1080: in _find_spec
???
.tox/py311/lib/python3.11/site-packages/_distutils_hack/init.py:97: in find_spec
return method()
.tox/py311/lib/python3.11/site-packages/_distutils_hack/init.py:147: in spec_for_pip
clear_distutils()
.tox/py311/lib/python3.11/site-packages/_distutils_hack/init.py:33: in clear_distutils
warnings.warn("Setuptools is replacing distutils.")
E UserWarning: Setuptools is replacing distutils.
The text was updated successfully, but these errors were encountered: