Skip to content
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

[BUG] Plotly Express (px) pandas datetime with timezone converted to UTC #2311

Closed
m0wer opened this issue Mar 25, 2020 · 12 comments · Fixed by #2749
Closed

[BUG] Plotly Express (px) pandas datetime with timezone converted to UTC #2311

m0wer opened this issue Mar 25, 2020 · 12 comments · Fixed by #2749
Milestone

Comments

@m0wer
Copy link

m0wer commented Mar 25, 2020

Similar to what happened in #209 Plotly Express converts the Pandas datetime object to UTC instead of respecting its timezone. If the datetime is a string or is converted to pydatetime it works as expected. A reproducible example is available at https://gist.github.com/m0wer/74d5a8901b9499795d13992d29cc2f0c.

A workaround (shown in the example) is to convert the datetime column of the Pandas DataFrame to pydatetime with:

df['date'].dt.to_pydatetime()
@amadeuspzs
Copy link

I can confirm this behaviour and also perceive it to be a bug

@nicolaskruchten nicolaskruchten added this to the 4.10 milestone Jul 20, 2020
@nicolaskruchten

This comment has been minimized.

@nicolaskruchten
Copy link
Contributor

Update: px.scatter(df, x='date', y='value') does not do what is expected per the changes we made in the 4.0 release (see https://plotly.com/python/v4-migration/#timezones), but go.Figure(go.Scatter(x=df["date"], y=df["value"])) does in this particular case... digging into why and what we can do about it.

@nicolaskruchten
Copy link
Contributor

I suspect this was introduced in #1934 because pulling the .values out of a series seems to strip the timezone information:

image

@jonmmease @alexcjohnson @emmanuelle should we fix this? The bug has been in the wild now much longer than the non-buggy code :(

@nicolaskruchten
Copy link
Contributor

Also cc @chriddyp would love your input on this one.

@nicolaskruchten
Copy link
Contributor

nicolaskruchten commented Aug 30, 2020

I'm thinking we should fix it... the only plots which will break are those where folks made plots with PX on an hourly-or-smaller timescale and fed in data with timezones but really wanted the plot to be in UTC and relied on the fact that it's automatic, which feels like a small set to me.

@alexcjohnson
Copy link
Collaborator

I think I agree we should fix it - px and non-px need to behave the same, and if / when we implement real timezone support in plotly.js the fixed version will still be compatible.

@nicolaskruchten
Copy link
Contributor

I should add that this only happens when the input is a pandas datetime column, not a column of ISO strings and not a numpy array of dates or that kind of thing.

@jonmmease
Copy link
Contributor

I would favor fixing this since it is a bug with respect to the v4 change log.

@emmanuelle
Copy link
Contributor

I also think we should fix it.

@amadeuspzs
Copy link

Thanks for fixing this I was coming here to file a bug report!

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 a pull request may close this issue.

6 participants