[BUG]: Single-color requests raise ZeroDivisionError in palette helpers
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- python
- Domain
- data-visualization
Research direction
The bug is in the plotly.colors helpers sample_colorscale and n_colors, which both divide by the requested count minus one. Start by running the reproduction script in the issue to confirm the ZeroDivisionError for a count of 1. Done when a single-color request returns one color at the start of the interval (low / lowcolor), matching the first sample of the multi-color case, and the zero-color case still returns an empty list.
Written by the indexing model from the issue text.
Description
Description
sample_colorscale and n_colors raise ZeroDivisionError when asked for one color. This breaks palettes sized to a dataset's group count when there is exactly one group. Both helpers divide by the requested count minus one.
Expected: one color from the start of the interval (low / lowcolor), consistent with their existing first sample.
Screenshots/Video
The API calls fail before a figure can be created; the output is shown below.
Steps to reproduce
from plotly.colors import n_colors, sample_colorscale
for label, call in [
("sample_colorscale", lambda: sample_colorscale("Viridis", 1)),
("n_colors", lambda: n_colors((0, 0, 0), (1, 1, 1), 1)),
]:
try:
print(label, call())
except ZeroDivisionError as error:
print(label, type(error).__name__, str(error))
Actual:
sample_colorscale ZeroDivisionError division by zero
n_colors ZeroDivisionError float division by zero
Expected:
sample_colorscale ['rgb(68, 1, 84)']
n_colors [(0.0, 0.0, 0.0)]
Notes
Reproduced with Plotly 7.1.0, current main 3f8a650930feadfdb651cd869ffe3e85fd093885, Python 3.12.10, Windows amd64. Zero-color requests already return empty lists.
- Dominant language
- Python
- Stars
- 18.8k
- Forks
- 2.9k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 20
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
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 plotly/plotly.py
-
[BUG]: Unnecessary `UserWarning` when using `fig.write_image()` with `kaleido.start_sync_server()`Possibly taken @jayzhou2309 claimed this 10 days ago. Openbug P3 size: 1
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
plotly/plotly.py#5786 · 1 comment ·
Maintainers usually reply within 1 day
-
P3 size: 1 task
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
plotly/plotly.py#5769 · 1 reaction ·
Maintainers usually reply within 1 day
-
Remove `@types/plotly.js` dependencyPossibly taken @Belagum claimed this 25 days ago. OpenP3 size: 1 task
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug P1
Difficulty 1/5 Under an hour Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
feature P3
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
All issues in plotly/plotly.py
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
lugassawan/swe-workbench#799 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
vllm-project/vllm#61131 ·
Maintainers usually reply within 1 day
-
Non-string form field names raise AttributeError when files are attachedPossibly taken @nightcityblade claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
kubernetes-client/python#2735 ·
Maintainers usually reply within 1 day
-
desktop help wanted test
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day