to_excel Mishandles Mixing of tz-aware datetimes · Issue #27008 · pandas-dev/pandas (original) (raw)

Code Sample, a copy-pastable example if possible

In [14]: import pandas as pd
In [14]: ew = pd.ExcelWriter('test.xlsx')

In [15]: df = pd.DataFrame([pd.to_datetime('2019-06-22 01:11'), pd.to_datetime('2019-06-22 01:11
    ...: Z'), pd.to_datetime('2019-06-22 01:11MSK')])

In [16]: df
Out[16]:
                           0
0        2019-06-22 01:11:00
1  2019-06-22 01:11:00+00:00
2  2019-06-22 01:11:00+03:00

In [17]: df.to_excel(ew, sheet_name='sh1')

In [18]: ew.save()

In [19]: ew.close()

(MSK is +03:00)

Problem description

ExcelWriter seems to incorrectly convert timestamps with timezones. Time part seems to be converted correctly, however date part looks like it was unchanged.

Expected excel sheet content

0 | 2019-06-22 01:11:00
1 | 2019-06-22 01:11:00
2 | 2019-06-21 22:11:00

Actual excel sheet content

0 | 2019-06-22 01:11:00
1 | 2019-06-22 01:11:00
2 | 2019-06-22 22:11:00

pandas is 0.24.2