ENH: add timezone awareness for formatting iso8601 datetimes to json
State: closed

This PR allows for non-UTC printing of datetime strings from the `to_json` method when passing in local timestamps

- [x]  closes #12997
- [x]  tests modified
- [ ]  Ensure all linting tests pass, see here for how to run them
- [x]  whatsnew entry
Ok, 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:
```
ts = pd.Timestamp('2020-10-5 4:00:05', tz='US/Pacific')
print(pd.io.json.dumps(ts, iso_dates=True))
print(ts.isoformat())
```
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!

Labels:
name: Enhancement
name: IO JSON
description: read_json, to_json, json_normalize
name: Timezones
description: Timezone data dtype
name: Stale

Comments:
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
Hello @jeliashi! Thanks for updating this PR. We checked the lines you've touched for [PEP 8](https://www.python.org/dev/peps/pep-0008) issues, and found:



There are currently no PEP 8 issues detected in this Pull Request. Cheers! :beers: 

##### Comment last updated at 2021-05-26 15:40:11 UTC
> 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.
@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.
> @mzeitlin11 @simonjayhawkins This is ready for review :)

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.