Exhibited there
from datetime import datetime
import pandas as pd
def test_json():
series = pd.Series(
[1., 2., 3.],
index=pd.date_range(datetime(2020, 1, 1), freq='H', periods=3)
)
jsonseries = series.to_json(date_format='iso')
assert jsonseries == (
'{"2020-01-01T00:00:00.000Z":1.0,'
'"2020-01-01T01:00:00.000Z":2.0,'
'"2020-01-01T02:00:00.000Z":3.0}'
)
series2 = pd.read_json(jsonseries, typ='series', dtype=False)
if pd.__version__.startswith('0.24'):
assert not getattr(series2.index.dtype, 'tz', False)
assert series.equals(series2)
elif pd.__version__.startswith('0.25'):
assert series2.index.dtype.tz.zone == 'UTC'
assert not series.equals(series2)
Problem description
In pandas 0.25, " Bug in read_json() where date strings with Z were not converted to a UTC timezone (GH26168) " made me realize an issue with series timestamp iso serialization.
Naive dates should not be converted within an UTC referential.
Comment From: WillAyd
This looks like an issue with to_json
adding the UTC specifier. Can you try on master? I think this may already be fixed
Comment From: zogzog
Ok I'll have a look.
Comment From: simonjayhawkins
This looks like an issue with
to_json
adding the UTC specifier. Can you try on master? I think this may already be fixed
unchanged on master
>>> from datetime import datetime
>>> import pandas as pd
>>>
>>> pd.__version__
'1.1.0.dev0+1047.g927dedb87'
>>>
>>> series = pd.Series(
... [1.0, 2.0, 3.0], index=pd.date_range(datetime(2020, 1, 1), freq="H", periods=3)
... )
>>> series.to_json(date_format="iso")
'{"2020-01-01T00:00:00.000Z":1.0,"2020-01-01T01:00:00.000Z":2.0,"2020-01-01T02:00:00.000Z":3.0}'
>>>
Comment From: lithomas1
This is fixed now, since (I think was same issue as #38760)