Skip to content

Fix single-color palette sampling - #5882

Open
i246506-Syeda-Khadija-Zaidi wants to merge 1 commit into
plotly:mainfrom
i246506-Syeda-Khadija-Zaidi:fix-single-color-palette
Open

i246506-Syeda-Khadija-Zaidi wants to merge 1 commit into
plotly:mainfrom
i246506-Syeda-Khadija-Zaidi:fix-single-color-palette

Conversation

@i246506-Syeda-Khadija-Zaidi

Copy link
Copy Markdown

Link to issue

Closes #5805

Description of change

Fixed division-by-zero errors when requesting a single color using n_colors() and sample_colorscale().

Both functions now correctly handle requests for one color by returning the first color in the requested range.

Demo

Not applicable. This change fixes color utility functions and does not introduce visual changes to Plotly charts.

Testing strategy

Added regression tests for both n_colors() and sample_colorscale() with a single-color request.

Ran python -m pytest tests/test_core/test_colors/test_colors.py -q — all 11 tests passed.

Additional information (optional)

This change ensures that requesting a single color does not result in a ZeroDivisionError.

Guidelines

  • i have reviewed the pull request guidelines and the Code of Conduct and confirm that this PR follows them.
  • I have added an entry to the changelog if needed.

@camdecoster

Copy link
Copy Markdown
Contributor

Hi! Thanks for the pull request. To help us deal with the increased volume of contributions we’re receiving, can you answer two questions about this work?

  • What’s your interest in making this change? Is it impacting your use of this library, and if so can you show us a concrete example? Or are you simply eager to improve the library for everyone else?
  • How involved were AI agents in this work? In particular, if this is primarily AI-driven work (which is fine, we use it too), it can be more efficient for us to simply take over the PR and hand it to our agents than to spend the time writing out comments.

We spend significant human effort reviewing each PR, so we really appreciate your help figuring out the best way to move this one toward merging. Thanks!

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

2 participants