pandas.Series.to_json() incorrectly localizes tz-naive datetimes to UTC · Issue #38760 · pandas-dev/pandas (original) (raw)
Seemingly related but not identical to #12997
How to reproduce the bug
Checked with pandas 0.24.2, 1.1.5 and 1.2.0.
import pandas as pd
index = pd.date_range(
start='2020-12-28 00:00:00',
end='2020-12-28 02:00:00',
freq='1H',
)
a = pd.Series(
data=range(3),
index=index,
)
a.to_json(date_format='iso')
Output
'{"2020-12-28T00:00:00.000Z":0,"2020-12-28T01:00:00.000Z":1,"2020-12-28T02:00:00.000Z":2}'
(Notice the "Z" indicating UTC)
Expected output
'{"2020-12-28T00:00:00.000":0,"2020-12-28T01:00:00.000":1,"2020-12-28T02:00:00.000":2}'
(without "Z")