python-visualization / python-visualization/branca

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

Offen
#222 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Python
Sterne
134
Forks
69
Ø Merge
1 Std. 10 Min.
Gemergte PRs (30 T.)
1

Beschreibung

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?

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in branca/colormap.py rund um LinearColormap.to_step, wo die Berechnung n - 1.0 bei n=1 einen Fehler auslöst, und reproduziere den im Issue beschriebenen Fehler. Ermittle das beabsichtigte Verhalten für einen einzelnen Schritt anhand der bestehenden API und der umgebenden Tests; abgeschlossen ist die Aufgabe, wenn das gewählte Verhalten implementiert, eindeutig spezifiziert und durch einen Regressionstest abgedeckt ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
58/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.