feature request: make graph_objects also dataframe agnostic
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.8k
- 平均合并
- 16 小时 26 分钟
- 30 天内合并 PR
- 21
描述
I was wondering, since narwhals was such a success in the plotly express api, whether the graph_objects api could get the same treatment. For the few trace types I tried (Scatter, Bar), arguments such as x, y, marker_color etc., accept tuple, list, numpy array, or pandas Series.
It would be great to be able to pass arrow or polars series as well, via narwhals, though I have no idea how feasible that would really be.
Desired outcome would be something like this:
"""
Fresh environment
>>> uv init
>>> uv add plotly polars
"""
import plotly.graph_objects as go
import polars as pl
df = pl.DataFrame({"x": [0, 1, 2, 3, 4], "y": [0, 1, 4, 9, 16]})
fig = go.Figure()
fig.add_trace(
go.Scatter(x=df["x"], y=df["y"]),
)
fig.show()
Currently one has to either transform to a list, pandas series, or if numpy is installed, there is some implicit transformation, which allows to pass polars series directly.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先通过 graph_objects API 复现提供的 polars 示例,重点关注使用 Scatter 和 Bar 的 go.Figure.add_trace。检查其 x、y 和 marker_color 参数当前如何处理列表、NumPy 数组和 pandas Series。当相关的 graph_objects trace 参数能够通过 narwhals 接受 polars 和 Arrow series,而无需转换时,即表示完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- data-visualization
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100