Skip to content

pandas.Series.to_json() incorrectly localizes tz-naive datetimes to UTC #38760

Closed
@simplydac

Description

@simplydac

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")

Metadata

Metadata

Assignees

Labels

BugIO JSONread_json, to_json, json_normalizeTimezonesTimezone data dtype

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions