Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Should LinearColormap.to_step(n=1) create a one-step colormap?

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

还没有人认领这个 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 a StepColormap with one color/bin?
  • Or should n <= 1 be explicitly rejected with a clear ValueError?
  • Or a mention in the docs stating that callers need to special-case single-class data?
主要语言
Python
星标
134
派生
69
平均合并
1 小时 10 分钟
30 天内合并 PR
1

贡献指南

这个仓库没有索引到贡献指南

从这里开始

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

python-visualization/branca 的其他 Issue

查看 python-visualization/branca 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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