From 00c3238b3fd1bda6c39b72897dc42b671b9b2d1b Mon Sep 17 00:00:00 2001 From: Joseph Damiba Date: Tue, 11 Feb 2020 17:50:40 -0500 Subject: [PATCH 1/7] prevent creation of new px.default properties at run time --- app.py | 10 ++++++++++ packages/python/plotly/plotly/express/_core.py | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 app.py diff --git a/app.py b/app.py new file mode 100644 index 0000000000..2df9fe3bc9 --- /dev/null +++ b/app.py @@ -0,0 +1,10 @@ +import plotly.express as px +px.defaults.template = "ggplot2" +px.defaults.color_continuous_scale = px.colors.sequential.Blackbody +px.defaults.width = 600 +px.defaults.height = 400 +px.defaults.blerd = "hlkjhlkjhjh" + +df = px.data.iris() +fig = px.scatter(df, x="sepal_width", y="sepal_length", color="sepal_length", width=400) +fig.show() \ No newline at end of file diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index db8f002c2c..2ab68e63c6 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -16,6 +16,8 @@ class PxDefaults(object): + __slots__ = ['template', 'width', 'height', 'color_discrete_sequence', 'color_continuous_scale', 'symbol_sequence', 'line_dash_sequence', 'size_max'] + def __init__(self): self.template = None self.width = None @@ -25,8 +27,7 @@ def __init__(self): self.symbol_sequence = None self.line_dash_sequence = None self.size_max = 20 - - + defaults = PxDefaults() del PxDefaults @@ -740,6 +741,7 @@ def one_group(x): def apply_default_cascade(args): # first we apply px.defaults to unspecified args + for param in ( ["color_discrete_sequence", "color_continuous_scale"] From 0eda9f828253eed40c821a03609e5c20fa56a89e Mon Sep 17 00:00:00 2001 From: Joseph Damiba Date: Tue, 11 Feb 2020 17:52:29 -0500 Subject: [PATCH 2/7] prevent creation of new px.default properties at run time --- app.py | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 app.py diff --git a/app.py b/app.py deleted file mode 100644 index 2df9fe3bc9..0000000000 --- a/app.py +++ /dev/null @@ -1,10 +0,0 @@ -import plotly.express as px -px.defaults.template = "ggplot2" -px.defaults.color_continuous_scale = px.colors.sequential.Blackbody -px.defaults.width = 600 -px.defaults.height = 400 -px.defaults.blerd = "hlkjhlkjhjh" - -df = px.data.iris() -fig = px.scatter(df, x="sepal_width", y="sepal_length", color="sepal_length", width=400) -fig.show() \ No newline at end of file From 633c2da5fd861086df4e5ff8581b5617f05e71a1 Mon Sep 17 00:00:00 2001 From: Joseph Damiba Date: Tue, 11 Feb 2020 17:59:33 -0500 Subject: [PATCH 3/7] run black --- packages/python/plotly/plotly/express/_core.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 2ab68e63c6..1f9e2706af 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -16,8 +16,17 @@ class PxDefaults(object): - __slots__ = ['template', 'width', 'height', 'color_discrete_sequence', 'color_continuous_scale', 'symbol_sequence', 'line_dash_sequence', 'size_max'] - + __slots__ = [ + "template", + "width", + "height", + "color_discrete_sequence", + "color_continuous_scale", + "symbol_sequence", + "line_dash_sequence", + "size_max", + ] + def __init__(self): self.template = None self.width = None @@ -27,7 +36,8 @@ def __init__(self): self.symbol_sequence = None self.line_dash_sequence = None self.size_max = 20 - + + defaults = PxDefaults() del PxDefaults @@ -741,7 +751,6 @@ def one_group(x): def apply_default_cascade(args): # first we apply px.defaults to unspecified args - for param in ( ["color_discrete_sequence", "color_continuous_scale"] From bae04837dfda371c407c9617ad151b4aac7f3c27 Mon Sep 17 00:00:00 2001 From: Joseph Damiba Date: Tue, 11 Feb 2020 20:33:28 -0500 Subject: [PATCH 4/7] add test for permissive defaults --- .../plotly/plotly/tests/test_core/test_px/test_px.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py index 9ace6a7b4a..6a283ede03 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py +++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py @@ -1,5 +1,7 @@ import plotly.express as px import numpy as np +import pytest + def test_scatter(): @@ -232,3 +234,9 @@ def assert_orderings(days_order, days_check, times_order, times_check): for days in permutations(df["day"].unique()): for times in permutations(df["time"].unique()): assert_orderings(days, days, times, times) + +def check_permissive_defaults(): + msg = "AttributeError: 'PxDefaults' object has no attribute 'should_not_work'" + with pytest.raises(AttributeError, match=msg): + px.defaults.should_not_work = "test" + \ No newline at end of file From 58aeb32627669340a9e7b01ae83973c109d260c7 Mon Sep 17 00:00:00 2001 From: Joseph Damiba Date: Tue, 11 Feb 2020 20:34:43 -0500 Subject: [PATCH 5/7] formatting --- .../python/plotly/plotly/tests/test_core/test_px/test_px.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py index 6a283ede03..a681442d88 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py +++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py @@ -3,7 +3,6 @@ import pytest - def test_scatter(): iris = px.data.iris() fig = px.scatter(iris, x="sepal_width", y="sepal_length") @@ -238,5 +237,4 @@ def assert_orderings(days_order, days_check, times_order, times_check): def check_permissive_defaults(): msg = "AttributeError: 'PxDefaults' object has no attribute 'should_not_work'" with pytest.raises(AttributeError, match=msg): - px.defaults.should_not_work = "test" - \ No newline at end of file + px.defaults.should_not_work = "test" \ No newline at end of file From 756f09bd3419713910ff27ce192039307dd646db Mon Sep 17 00:00:00 2001 From: Joseph Damiba Date: Tue, 11 Feb 2020 20:35:32 -0500 Subject: [PATCH 6/7] formatting --- .../python/plotly/plotly/tests/test_core/test_px/test_px.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py index a681442d88..d04e97809f 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py +++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py @@ -234,7 +234,8 @@ def assert_orderings(days_order, days_check, times_order, times_check): for times in permutations(df["time"].unique()): assert_orderings(days, days, times, times) + def check_permissive_defaults(): msg = "AttributeError: 'PxDefaults' object has no attribute 'should_not_work'" with pytest.raises(AttributeError, match=msg): - px.defaults.should_not_work = "test" \ No newline at end of file + px.defaults.should_not_work = "test" From bdda85167e0bde72bda70d0f5f18ec9a6554fd78 Mon Sep 17 00:00:00 2001 From: Joseph Damiba Date: Wed, 12 Feb 2020 10:59:25 -0500 Subject: [PATCH 7/7] make sure new test is picked up by pytest --- .../python/plotly/plotly/tests/test_core/test_px/test_px.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py index d04e97809f..b4880899e9 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py +++ b/packages/python/plotly/plotly/tests/test_core/test_px/test_px.py @@ -235,7 +235,7 @@ def assert_orderings(days_order, days_check, times_order, times_check): assert_orderings(days, days, times, times) -def check_permissive_defaults(): - msg = "AttributeError: 'PxDefaults' object has no attribute 'should_not_work'" +def test_permissive_defaults(): + msg = "'PxDefaults' object has no attribute 'should_not_work'" with pytest.raises(AttributeError, match=msg): px.defaults.should_not_work = "test"