Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Stop auto-converting timezones to UTC and stripping timezone info #1581

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

Merged
jonmmease merged 3 commits into master from enh_timezones
May 27, 2019

Conversation

@jonmmease
Copy link
Contributor

@jonmmease jonmmease commented May 27, 2019

Overview

This PR introduces a new v4 timezones future flag that changes the behavior of datetime serialization in plotly.py.

The current (version 3) behavior for datetimes with timezone info is for plotly.py to automatically convert datetimes to UTC and then remove the timezone info during serialization. This has resulted in a lot of confusion over the years (See #209).

The new behavior is for plotly.py to stop performing the UTC conversion and leave the timezone info in the string that is passed along to plotly.js. Plotly.js currently drops the timezone info (plotly/plotly.js#1532) and displays everything in local time, but hopefully at some point in the future Plotly.js will process the timezone info and provide a way to specify the desired display timezone in the figure specification.

Example

v3 behavior

from _plotly_future_ import renderer_defaults
import plotly.graph_objs as go
import plotly.io as pio
import pandas as pd
import sys, datetime
x1 = pd.to_datetime(
 ['2015-04-04 12:00:00', '2015-04-04 13:00:00', '2015-04-04 15:00:00'])
x2 = x1.tz_localize('UTC').tz_convert('US/Eastern')
fig1 = go.Figure(data=[go.Scatter(x=x2, y=[1, 3, 2])])
fig1

newplot-1

print(pio.to_json(fig1, pretty=True))
{
 "data": [
 {
 "type": "scatter",
 "x": [
 "2015-04-04 12:00:00",
 "2015-04-04 13:00:00",
 "2015-04-04 15:00:00"
 ],
 "y": [
 1,
 3,
 2
 ]
 }
 ],
 "layout": {}
}

v4 behavior

from _plotly_future_ import renderer_defaults, timezones
import plotly.graph_objs as go
import plotly.io as pio
import pandas as pd
import sys, datetime
x1 = pd.to_datetime(
 ['2015-04-04 12:00:00', '2015-04-04 13:00:00', '2015-04-04 15:00:00'])
x2 = x1.tz_localize('UTC').tz_convert('US/Eastern')
fig1 = go.Figure(data=[go.Scatter(x=x2, y=[1, 3, 2])])
fig1

newplot-2

print(pio.to_json(fig1, pretty=True))
{
 "data": [
 {
 "type": "scatter",
 "x": [
 "2015-04-04T08:00:00-04:00",
 "2015-04-04T09:00:00-04:00",
 "2015-04-04T11:00:00-04:00"
 ],
 "y": [
 1,
 3,
 2
 ]
 }
 ],
 "layout": {}
}

cc @nicolaskruchten @chriddyp @alexcjohnson

VldmrB and n0mer reacted with thumbs up emoji KieranWynn reacted with heart emoji
Copy link
Contributor

This seems like the right thing to do overall: match the plotly.js API more closely such that the day plotly.js handles timezones more gracefully it'll just flow through.

Copy link
Contributor Author

To try out the dev build:

$ pip install https://13363-14579099-gh.circle-artifacts.com/0/dist/plotly-3.9.0%2B9.gdc776963.tar.gz

Then start your python notebook/script with

from _plotly_future_ import timezones

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

v3.10

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /