Skip to content

ENH: add abiility for json.dumps to parse and add timezones #41667

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

Conversation

jeliashi
Copy link

@jeliashi jeliashi commented May 25, 2021

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 provide
"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!

@jeliashi jeliashi changed the title add abiility for json.dumps to parse and add timezones ENH: add abiility for json.dumps to parse and add timezones May 25, 2021
@pep8speaks
Copy link

pep8speaks commented May 25, 2021

Hello @jeliashi! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

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

Comment last updated at 2021-05-26 15:36:58 UTC

Copy link
Member

@simonjayhawkins simonjayhawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeliashi can you close this one and carry on with #41573 if possible, much easier to track.

@jeliashi
Copy link
Author

@jeliashi can you close this one and carry on with #41573 if possible, much easier to track.

sure thing

@jeliashi jeliashi closed this May 26, 2021
@jeliashi jeliashi reopened this May 26, 2021
@jeliashi jeliashi closed this May 26, 2021
@jeliashi jeliashi deleted the jeliashi-apply-timezone-offset-for-creating-iso8601 branch May 26, 2021 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

to_json converts to UTC when encoding ISO formatted datetimes
3 participants