From 66b6782659aa0275ac4c2bea0bfb5ab782aaf385 Mon Sep 17 00:00:00 2001 From: Isaac Virshup Date: Thu, 2 Aug 2018 11:26:41 +1000 Subject: [PATCH 1/3] Added tests for colorscales specified as a string Added tests checking that a colorscale specified as a string is returned correctly. Previously it had been returned as a tuple of 1-tuples. e.g. "Viridis" -> (('V',), ('i',), ('r',), ('i',), ('d',), ('i',), ('s',)). Catches #1087. --- .../tests/validators/test_colorscale_validator.py | 2 ++ .../test_graph_objs/test_properties_validated.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/_plotly_utils/tests/validators/test_colorscale_validator.py b/_plotly_utils/tests/validators/test_colorscale_validator.py index 74ffb41877e..c179ff39587 100644 --- a/_plotly_utils/tests/validators/test_colorscale_validator.py +++ b/_plotly_utils/tests/validators/test_colorscale_validator.py @@ -26,6 +26,8 @@ def test_acceptance_named(named_colorscale, validator: ColorscaleValidator): # Uppercase assert (validator.validate_coerce(named_colorscale.upper()) == named_colorscale.upper()) + + assert validator.present(named_colorscale) == named_colorscale # ### Acceptance as array ### @pytest.mark.parametrize('val', [ diff --git a/plotly/tests/test_core/test_graph_objs/test_properties_validated.py b/plotly/tests/test_core/test_graph_objs/test_properties_validated.py index a7e25c99021..897b2104c7a 100644 --- a/plotly/tests/test_core/test_graph_objs/test_properties_validated.py +++ b/plotly/tests/test_core/test_graph_objs/test_properties_validated.py @@ -102,6 +102,16 @@ def test_present_colorscale(self): # Presented as tuple of tuples self.assertEqual(self.scatter.marker.colorscale, ((0, 'red'), (1, 'green'))) + + def test_present_colorscale_str(self): + self.assertIsNone(self.scatter.marker.colorscale) + + # Assign string + self.scatter.marker.colorscale = "Viridis" + + # Presented as a string + self.assertEqual(self.scatter.marker.colorscale, + "Viridis") class TestPropertyIterContains(TestCase): From 5aff631cac116078b7741efe96b06d3237ea661c Mon Sep 17 00:00:00 2001 From: Isaac Virshup Date: Thu, 2 Aug 2018 11:49:07 +1000 Subject: [PATCH 2/3] Fix presentation of string colorscales Fixes #1087. --- _plotly_utils/basevalidators.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/_plotly_utils/basevalidators.py b/_plotly_utils/basevalidators.py index d094e27aae6..9e7d2036501 100644 --- a/_plotly_utils/basevalidators.py +++ b/_plotly_utils/basevalidators.py @@ -1274,9 +1274,11 @@ def validate_coerce(self, v): return v def present(self, v): - # Return tuple of tuples so that colorscale is immutable + # Return-type must be immutable if v is None: return None + elif isinstance(v, string_types): + return v else: return tuple([tuple(e) for e in v]) From f793faafaff821ac0622082c83a7497b189c8d5f Mon Sep 17 00:00:00 2001 From: Isaac Virshup Date: Mon, 6 Aug 2018 10:55:00 +1000 Subject: [PATCH 3/3] Added support for Cividis to ColorScaleValidator --- _plotly_utils/basevalidators.py | 4 ++-- _plotly_utils/tests/validators/test_colorscale_validator.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/_plotly_utils/basevalidators.py b/_plotly_utils/basevalidators.py index 9e7d2036501..81c413b4c46 100644 --- a/_plotly_utils/basevalidators.py +++ b/_plotly_utils/basevalidators.py @@ -1211,7 +1211,7 @@ class ColorscaleValidator(BaseValidator): named_colorscales = [ 'Greys', 'YlGnBu', 'Greens', 'YlOrRd', 'Bluered', 'RdBu', 'Reds', 'Blues', 'Picnic', 'Rainbow', 'Portland', 'Jet', 'Hot', 'Blackbody', - 'Earth', 'Electric', 'Viridis' + 'Earth', 'Electric', 'Viridis', 'Cividis' ] def __init__(self, plotly_name, parent_name, **kwargs): @@ -1229,7 +1229,7 @@ def description(self): - One of the following named colorscales: ['Greys', 'YlGnBu', 'Greens', 'YlOrRd', 'Bluered', 'RdBu', 'Reds', 'Blues', 'Picnic', 'Rainbow', 'Portland', 'Jet', - 'Hot', 'Blackbody', 'Earth', 'Electric', 'Viridis'] + 'Hot', 'Blackbody', 'Earth', 'Electric', 'Viridis', 'Cividis] """.format(plotly_name=self.plotly_name) return desc diff --git a/_plotly_utils/tests/validators/test_colorscale_validator.py b/_plotly_utils/tests/validators/test_colorscale_validator.py index c179ff39587..fa2dda20e4d 100644 --- a/_plotly_utils/tests/validators/test_colorscale_validator.py +++ b/_plotly_utils/tests/validators/test_colorscale_validator.py @@ -11,7 +11,8 @@ def validator(): @pytest.fixture(params=['Greys', 'YlGnBu', 'Greens', 'YlOrRd', 'Bluered', 'RdBu', 'Reds', 'Blues', - 'Picnic', 'Rainbow', 'Portland', 'Jet', 'Hot', 'Blackbody', 'Earth', 'Electric', 'Viridis']) + 'Picnic', 'Rainbow', 'Portland', 'Jet', 'Hot', 'Blackbody', 'Earth', 'Electric', + 'Viridis', 'Cividis']) def named_colorscale(request): return request.param