python-visualization / python-visualization/branca

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

オープン
#222 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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 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?

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. 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

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。