You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
lithomas1
added
IO JSON
read_json, to_json, json_normalize
Non-Nano
datetime64/timedelta64 with non-nanosecond resolution
and removed
Needs Triage
Issue that has not been reviewed by a pandas team member
labels
Jun 19, 2023
I think I see what's going on. In the JSON C code when converting the numpy datetimes to strings, we assume that the datetime has nanosecond resolution (non-nano support in pandas is still newish).
Uh oh!
There was an error while loading. Please reload this page.
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
With a DataFrame in which the DatetimeIndex precision has been set to us, the json representation is incorrect.
With the usual initialization, the DatetimeIndex has precision ns, and it works fine:
If the precision is changed (I tried it as a workaround of issue #53684 ), the date is incorrect in
to_json
:The
date_unit
parameter doesn't help, the date is still incorrect.Other precisions fail too:
Expected Behavior
The output of
to_json
in iso format should be'{"testcol":{"2023-01-01T11:22:33.123456":12}}'
Installed Versions
INSTALLED VERSIONS
commit : 965ceca
python : 3.10.8.final.0
python-bits : 64
OS : Linux
OS-release : 4.12.14-195-default
Version : #1 SMP Tue May 7 10:55:11 UTC 2019 (8fba516)
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 2.0.2
numpy : 1.24.3
pytz : 2023.3
dateutil : 2.8.2
setuptools : 63.2.0
pip : 22.2.2
Cython : None
pytest : 7.3.1
hypothesis : None
sphinx : 7.0.1
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.13.2
pandas_datareader: None
bs4 : 4.12.2
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: