Repository navigation
Fix sample_colorscale crash for colorscales that use CSS named colors - #5931
Open
rashedrana wants to merge 2 commits into
Open
rashedrana wants to merge 2 commits into
rashedrana wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5930
Problem:
plotly.colors.sample_colorscaleraisesTypeError: unsupported operand type(s) for -: 'str' and 'str'when a colorscale uses CSS named colors (for example "red" or "blue"), in both the list of [scale, color] pairs form and the list of colors form. Named colors are valid plotly colors:validate_colorscaleaccepts such a colorscale and so do graph objects.Repro:
Fix: in
_plotly_utils/colors/__init__.py,validate_colorsnow converts CSS named colors to color tuples, like it already does for rgb and hex strings, so they are interpolated as tuples instead of reachingfind_intermediate_coloras strings. The name to RGB mapping (_NAMED_COLORS) covers the CSS Color 4 named colors, the same set of names accepted byColorValidator. The lookup is case-insensitive, and named colors can be mixed with hex, rgb, rgba and tuple colors in one colorscale.Test result: the repro now returns
['rgb(255, 0, 0)', 'rgb(128, 0, 128)', 'rgb(0, 0, 255)']for both colorscale forms, matching the hex equivalent. A regression test,test_sample_colorscale_named_colors, was added totests/test_core/test_colors/test_colors.py; it fails with the TypeError above without the fix and passes with it. The full test module passes (10 tests).Prepared with AI assistance and verified locally by me.