Skip to content

Polars timezone not respected in graph_objects.scatter #5226

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

Open
kevinleahy-switchdin opened this issue Jun 10, 2025 · 1 comment
Open

Polars timezone not respected in graph_objects.scatter #5226

kevinleahy-switchdin opened this issue Jun 10, 2025 · 1 comment

Comments

@kevinleahy-switchdin
Copy link

latest version of plotly // python 3.12

from datetime import datetime, timedelta
from zoneinfo import ZoneInfo

import pandas as pd
import polars as pl

daterange = [datetime(2023, 1, 1, tzinfo=ZoneInfo("Australia/Brisbane")) + timedelta(hours=i) for i in range(48)]

df_1 = pl.DataFrame(
    {
        "timestamp": daterange,
        "line1": [0.1] * 24 + [0.2] * 24,
    }
)
df_2 = pl.DataFrame(
    {
        "timestamp": daterange,
        "line2": [0.0] * 24 + [0.4] * 24,
    }
)
fig = px.line(df_1, x="timestamp", y="line1")

fig.add_trace(
    go.Scatter(
        x=df_2["timestamp"],
        y=df_2["line2"],
        name="line2",
    )
)
fig.show()

"line1" (using px.line )renders correctly with local time on the X-axis. But "line2" (using go.Scatter) gets converted to UTC.

This goes away if df_2 uses pandas or I pass in df_2['timestamp'].to_list() instead.

Probably related to #5166 - is this just because polars isn't supported, but since we've not got type hints in plotly my IDE wasn't complaining?

@MarcoGorelli
Copy link
Contributor

thanks for the report - yeah iirc going through plotly directly (as opposed to plotly.express) will just convert to numpy, so it would get an array of timestamps at the corresponding utc times?

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

No branches or pull requests

2 participants