-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
to_excel Mishandles Mixing of tz-aware datetimes #27008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think this is happening because you are mixing tz-aware and tz-naive timestamps. This seems to work: df = pd.DataFrame([pd.to_datetime('2019-06-22 01:11Z'), pd.to_datetime('2019-06-22 01:11Z'), pd.to_datetime('2019-06-22 01:11:00+03')])
df.to_excel('foo.xlsx') If you'd like to take a look would certainly take a PR |
Unfortunately no.
this one, with timezone, also gives incorrect result - 2019-06-22 22:11:00. |
Hmm OK. Interestingly enough if you use the xlsxwriter this will fail: >>> df.to_excel('~/Desktop/foo.xlsx', engine='xlsxwriter')
TypeError: Excel doesn't support timezones in datetimes. Set the tzinfo in the datetime/time object to None or use the 'remove_timezone' Workbook() option Is your expectation to just have everything converted to UTC? |
Initially I wanted it in my local timezone so it seems that the solution would be to remove tz information so that no conversion takes place. |
The catch is that in your original example not all Timestamps have a timezone, so conversion to a local timezone wouldn't be entirely applicable. @mroeschke do we have a standard way of dealing with IO conversions for timestamps when timezone information isn't supported? |
For SQL, we export xref Another excel timezone export issue: #7056 |
Just to clarify - the problem reproduces not only in the mixed use case I've mentioned initially. Just one cell with tz-aware datetime produces incorrect result. |
Thanks for the ref @mroeschke . Per this comment #7056 (comment) I think this should raise @shashurup what do you think about that? The problem here is that the intention is rather ambiguous so by raising it would at least indicate that to the end user that further steps would need to be taken to make the intention clearer |
I agree that the intention must be clarified, i.e. the timezone we want Excel to display must be specified somehow. |
Note, the date you are passing gets dispatched to dateutil, and while pandas's current minimum dateutil version supports parsing
|
Code Sample, a copy-pastable example if possible
(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
The text was updated successfully, but these errors were encountered: