Skip to content

ColorScaleValidator should probably return a string when it's specified as a string. #1087

Closed
@ivirshup

Description

@ivirshup

Currently, color scale attributes have a kinda weird behavior:

import plotly.graph_objs as go
go.scatter.Marker(colorscale="Viridis").colorscale
(('V',), ('i',), ('r',), ('i',), ('d',), ('i',), ('s',))

This is unlike the behavior (to the best of my knowledge) for other attributes specified as strings:

go.scatter.Marker(color="red").color
'red'

And this is pretty unintuitive behavior when doing stuff like:

marker1 = go.scatter.Marker(colorscale="Viridis")
go.scatter.Marker(colorscale=marker1.colorscale)
ValueError: 
    Invalid value of type 'builtins.tuple' received for the 'colorscale' property of scatter.marker
        Received value: (('V',), ('i',), ('r',), ('i',), ('d',), ('i',), ('s',))

Though .update(marker1) does work for some reason.

My guess is all that needs to happen is to add an elif isinstance(v, str): return v to this function, since you won't be breaking that immutability requirement.

def present(self, v):
# Return tuple of tuples so that colorscale is immutable
if v is None:
return None
else:
return tuple([tuple(e) for e in v])

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions