plotly / plotly/plotly.py

Polars timezone not respected in graph_objects.scatter

Open
#5,226 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P2
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

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 https://github.com/plotly/plotly.py/issues/5166 - is this just because polars isn't supported, but since we've not got type hints in plotly my IDE wasn't complaining?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Python reproduction, comparing px.line with go.Scatter when x is a Polars timestamp Series versus a list or pandas data. Trace the conversion path used by go.Scatter and verify how timezone information is handled. Done means the Polars Series preserves the local timezone consistently and the reproduction renders both traces with matching time values.

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.