[BUG]: Single-color requests raise ZeroDivisionError in palette helpers
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
调研方向
问题出在 plotly.colors 辅助函数 sample_colorscale 和 n_colors 中,它们都除以请求的数量减一。首先运行 issue 中的复现脚本,确认数量为 1 时会抛出 ZeroDivisionError。当请求单个颜色时返回区间起点(low / lowcolor)处的一个颜色,与多颜色情况的第一个采样结果一致,并且零颜色的情况仍然返回空列表,即为完成。
由索引模型根据 Issue 内容生成。
描述
Description
sample_colorscale and n_colors raise ZeroDivisionError when asked for one color. This breaks palettes sized to a dataset's group count when there is exactly one group. Both helpers divide by the requested count minus one.
Expected: one color from the start of the interval (low / lowcolor), consistent with their existing first sample.
Screenshots/Video
The API calls fail before a figure can be created; the output is shown below.
Steps to reproduce
from plotly.colors import n_colors, sample_colorscale
for label, call in [
("sample_colorscale", lambda: sample_colorscale("Viridis", 1)),
("n_colors", lambda: n_colors((0, 0, 0), (1, 1, 1), 1)),
]:
try:
print(label, call())
except ZeroDivisionError as error:
print(label, type(error).__name__, str(error))
Actual:
sample_colorscale ZeroDivisionError division by zero
n_colors ZeroDivisionError float division by zero
Expected:
sample_colorscale ['rgb(68, 1, 84)']
n_colors [(0.0, 0.0, 0.0)]
Notes
Reproduced with Plotly 7.1.0, current main 3f8a650930feadfdb651cd869ffe3e85fd093885, Python 3.12.10, Windows amd64. Zero-color requests already return empty lists.
- 主要语言
- Python
- 星标
- 18.8k
- 派生
- 2.9k
- 平均合并
- 3 天 7 小时
- 30 天内合并 PR
- 20
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
plotly/plotly.py 的其他 Issue
-
README Quickstart fails after `pip install plotly` (numpy and pandas missing)可能已有人在做 @DawnofGenX 于 5 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
plotly/plotly.py#5790 · 1 条评论 ·
维护者通常 1 天内回复
-
[BUG]: Unnecessary `UserWarning` when using `fig.write_image()` with `kaleido.start_sync_server()`可能已有人在做 @jayzhou2309 于 9 天前认领。 未关闭bug P3 size: 1
难度 2/5 1-3 小时 新手友好度 74/100
plotly/plotly.py#5786 · 1 条评论 ·
维护者通常 1 天内回复
-
P3 size: 1 task
难度 2/5 1-3 小时 新手友好度 65/100
plotly/plotly.py#5769 · 1 个 reaction ·
维护者通常 1 天内回复
-
Remove `@types/plotly.js` dependency可能已有人在做 @Belagum 于 25 天前认领。 未关闭P3 size: 1 task
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug P1
难度 1/5 1 小时以内 新手友好度 68/100
维护者通常 1 天内回复
相似的 Issue
-
[BUG] Container scenario crashes without expected_recovery_time, kube DNS example uses retry_wait未关闭needs-triage
难度 2/5 1-3 小时 新手友好度 77/100
krkn-chaos/krkn#1627 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
NousResearch/hermes-agent#136483 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
[BUG] LazyStackedTensorDictStore zeroes the last byte of a new key set on the last element可能已有人在做 @peterdsharpe 今天认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 78/100
pytorch/tensordict#2307 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复