Should LinearColormap.to_step(n=1) create a one-step colormap?
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 58/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- data-visualization
Research direction
Start in branca/colormap.py around LinearColormap.to_step, where the n - 1.0 calculation raises for n=1, and reproduce the failure from the issue. Determine the intended single-step behavior from the existing API and surrounding tests; done means the chosen behavior is implemented, clearly specified, and covered by a regression test.
Written by the indexing model from the issue text.
Description
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?
- Dominant language
- Python
- Stars
- 134
- Forks
- 69
- Avg merge
- 1h 10m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-visualization/branca
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
python-visualization/branca#213 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 42/100
python-visualization/branca#195 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
python-visualization/branca#190 · 6 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
python-visualization/branca#182 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 30/100
python-visualization/branca#174 · 9 comments ·
All issues in python-visualization/branca
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
anthropics/skills#1811 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
speaches-ai/speaches#678 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
datalayer/mcp-compose#42 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conda-forge/spacy-feedstock#177 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
UKGovernmentBEIS/inspect_evals#2523 ·