Skip to content

Fix single-color palette generation - #5806

Open
MokiMeow wants to merge 1 commit into
plotly:mainfrom
MokiMeow:fix-single-color-palette-5805
Open

MokiMeow wants to merge 1 commit into
plotly:mainfrom
MokiMeow:fix-single-color-palette-5805

Conversation

@MokiMeow

Copy link
Copy Markdown

Link to issue

Closes #5805

Description of change

Allow sample_colorscale and n_colors to return one color from the lower endpoint instead of raising ZeroDivisionError. Interpolation for larger palettes stays unchanged.

Demo

from plotly.colors import sample_colorscale, n_colors
sample_colorscale("Viridis", 1)  # ['rgb(68, 1, 84)']
n_colors((0, 0, 0), (1, 1, 1), 1)  # [(0.0, 0.0, 0.0)]

Both calls raise before the fix.

Testing strategy

Eight regression cases fail before the fix; all 14 new cases pass afterward. Colors tests: 40 passed on Python 3.8; broader Windows runs: 1898 passed on Python 3.12 and 468 on Python 3.8.

Additional information

The broader runs omit a reproduced Windows-only hierarchy test and, on 3.12, the existing Inferno_r validator failure. Changed-file lint and full formatting pass; broad Ruff retains the same 1911 baseline errors. Sdist/wheel, installed-wheel consumer and focused API documentation checks pass.

Guidelines

  • I have reviewed the contributing guidelines and Code of Conduct.
  • I have added a changelog entry.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Single-color requests raise ZeroDivisionError in palette helpers

1 participant