python-visualization / python-visualization/branca
Should LinearColormap.to_step(n=1) create a one-step colormap?
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 134
- フォーク
- 69
- 平均マージ
- 1時間 10分
- マージ済み PR(30日)
- 1
説明
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?
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
branca/colormap.py の LinearColormap.to_step 周辺から始め、n=1 のときに n - 1.0 の計算でエラーが発生することを確認し、issue の失敗を再現してください。既存の API と周辺のテストから、単一ステップで意図されている動作を判断してください。選択した動作が実装され、明確に仕様化され、回帰テストでカバーされていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- data-visualization
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 58/100