Should LinearColormap.to_step(n=1) create a one-step colormap?
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 58/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- python
调研方向
从 branca/colormap.py 中 LinearColormap.to_step 附近开始,这里的 n - 1.0 计算会在 n=1 时引发错误,并重现 issue 中的失败。根据现有 API 和周围的测试,确定单步操作的预期行为;当所选行为已实现、有明确说明,并由回归测试覆盖时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
LinearColormap(...).to_step(n=1) raises a ZeroDivisionError.
In map/choropleth workflows, after filtering or classification, there may be only one bucket/class to display, and a one-step colormap seems semantically reasonable.
Currently, we get:
❯ uv run --with branca python
Python 3.12.3 (main, Mar 23 2026, 19:04:32) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import branca
>>> from branca.colormap import LinearColormap
>>> print(branca.__version__)
0.8.2
>>>
>>> cm = LinearColormap(["red", "blue"], vmin=0, vmax=1)
>>> cm.to_step(n=1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".../branca/colormap.py", line 450, in to_step
index[i] * (1.0 - i / (n - 1.0)) + index[i + 1] * i / (n - 1.0),
~~^~~~~~~~~~~
ZeroDivisionError: float division by zero
The API says n is the expected number of colors in the output StepColormap. When no index/data is supplied it constructs a regular grid from n; later, it computes colors using n - 1.0, which fails at n=1.
Possibilities:
- Could
to_step(n=1)to return aStepColormapwith one color/bin? - Or should
n <= 1be explicitly rejected with a clearValueError? - Or a mention in the docs stating that callers need to special-case single-class data?
- 主要语言
- Python
- 星标
- 134
- 派生
- 69
- 平均合并
- 1 小时 10 分钟
- 30 天内合并 PR
- 1
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-visualization/branca 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 45/100
python-visualization/branca#213 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 42/100
python-visualization/branca#195 ·
-
bug
难度 2/5 1-3 小时 新手友好度 45/100
python-visualization/branca#190 · 6 条评论 ·
-
难度 3/5 1-2 天 新手友好度 35/100
python-visualization/branca#182 ·
-
难度 3/5 1-2 天 新手友好度 30/100
python-visualization/branca#174 · 9 条评论 ·
查看 python-visualization/branca 的全部 Issue
相似的 Issue
-
essnmx good first issue
难度 1/5 1 小时以内 新手友好度 95/100
-
难度 2/5 1-3 小时 新手友好度 65/100
syfoud/Simulated_Scepter#174 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
Giskard-AI/giskard-oss#2840 · 1 条评论 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success 未关闭area: repo bug perceived difficulty: 2
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
yeti-platform/yeti#1380 ·