Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plotly.colors.validate_colors fails for valid colors and passes for invalid colors #4957

Open
mboll opened this issue Jan 8, 2025 · 0 comments
Labels
bug something broken P2 considered for next cycle

Comments

@mboll
Copy link

mboll commented Jan 8, 2025

This function raises a PlotlyError for color formats that are valid within traces, but also does not raise errors for color formats that are not valid.

Example of a valid color string that does not pass: color = 'hsl(290, 100%, 50%)'. This works perfectly fine if you construct a trace with it, but fails the validation test because it does not contain "rgb" or "#".

import plotly.graph_objects as go
import plotly.colors as pc

color = 'hsl(290, 100%, 50%)'

# this works
trace = go.Scatter(x=[0], y=[0], marker=dict(color=color))
fig = go.Figure(trace)
fig.show()

# this does not
pc.validate_colors(color)  # this throws an error

Other cases:

  • A valid, named color string throws an error
  • The same named color within a list does not throw an error
  • An invalid named color within a list does not throw an error, but it should

Examples below

import plotly.colors as pc

pc.validate_colors('red')  # throws PlotlyError

pc.validate_colors(['red'])
>>> ['red']

pc.validate_colors(['asdflkjlaskdg'])
>>> ['asdflkjlaskdg']

Perhaps this function is not meant to be used in this way? If so then more information in the docstrings could be helpful.

Plotly version 5.24.1.

@gvwilson gvwilson added bug something broken P2 considered for next cycle labels Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P2 considered for next cycle
Projects
None yet
Development

No branches or pull requests

2 participants