plotly / plotly/plotly.py

Polars timezone not respected in graph_objects.scatter

未关闭
#5,226 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P2
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

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?

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从提供的 Python 复现开始,在 x 为 Polars timestamp Series 而不是列表或 pandas 数据时,对比 px.line 与 go.Scatter。跟踪 go.Scatter 使用的转换路径,并验证时区信息是如何处理的。完成标准是 Polars Series 始终保留本地时区,并且复现结果以匹配的时间值渲染两条轨迹。

由索引模型根据 Issue 内容生成。

评估

技术栈
pandas, python
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。