-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
ENH: add timezone awareness for formatting iso8601 datetimes to json #41573
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
ENH: add timezone awareness for formatting iso8601 datetimes to json #41573
Conversation
Thanks for the pr @jeliashi! Looks like build failing (maybe from warnings you see locally that are errors with our CI flags) (https://dev.azure.com/pandas-dev/pandas/_build/results?buildId=60052&view=logs&j=b516280a-8c75-541b-8ba0-ae13561718a7&t=2bc93ab4-1a3f-5fe5-4e3f-0d861e20f7c6&l=721) Also, this looks like a pretty large change - needs testing! That would also be helpful to make clear what this behavior change is |
Hi @mzeitlin11, I've actually made it bigger now lol. Sorry about that. I'll add testing in a bit to account for the new features this branch provides. This now should compile everywhere! Excited to be contributing. I use pandas almost every work day so it feels good to fix a bug that has been bothering me for a while. |
a50af89
to
4f72070
Compare
@mzeitlin11 @simonjayhawkins This is ready for review :) |
This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this. |
ci is failing. can you fix-up to pass and move release note to 1.4 |
Thanks for the PR, but it appears this PR has gone stale. Closing due to inactivity but please let us know if you're still interested in working on this and we can reopen. |
This PR allows for non-UTC printing of datetime strings from the
to_json
method when passing in local timestampsOk, so this is a doozy AND it's not done, but it can be merged as is.
What do we do:
We add timezones to json output!
Before:
would produce
"2020-10-05T11:00:05.000Z"
and
"2020-10-05T04:00:05.000-07:00"
respectively.
Now they both produce
"2020-10-05T04:00:05.000-07:00"
So what do I mean by not complete?
This still doesn't work for arrays that have datetime values. This only works for single datetime values.
So:
pd.DataFrame({'foo': range(5)}, index=pd.date_range('2020-10-12', freq='H', periods=5, tz='US/Eastern')).to_json(date_format='iso')
will still produce:
'{"foo":{"2020-10-12T04:00:00.000Z":0,"2020-10-12T05:00:00.000Z":1,"2020-10-12T06:00:00.000Z":2,"2020-10-12T07:00:00.000Z":3,"2020-10-12T08:00:00.000Z":4}}'
and not
'{"foo":{"2020-10-12T00:00:00.000-04:00":0,"2020-10-12T01:00:00.000-04:00":1,"2020-10-12T02:00:00.000-04:00":2,"2020-10-12T03:00:00.000-04:00":3,"2020-10-12T04:00:00.000-04:00":4}}'
Working on it currently. Open to recommendations!