From e92682deb53d228d92eb1357ae3f6af9bd114736 Mon Sep 17 00:00:00 2001 From: hannah Date: Mon, 25 May 2020 04:19:04 -0400 Subject: [PATCH 1/5] added integration tests --- lib/matplotlib/tests/test_preprocess_data.py | 38 ++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/tests/test_preprocess_data.py b/lib/matplotlib/tests/test_preprocess_data.py index a24184e1e43c..4f1fc670fb94 100644 --- a/lib/matplotlib/tests/test_preprocess_data.py +++ b/lib/matplotlib/tests/test_preprocess_data.py @@ -4,7 +4,8 @@ import pytest from matplotlib import _preprocess_data - +from matplotlib.axes import Axes +from matplotlib.testing.decorators import check_figures_equal # Notes on testing the plotting functions itself # * the individual decorated plotting functions are tested in 'test_axes.py' @@ -72,11 +73,18 @@ def test_function_call_without_data(func): assert (func(None, x="x", y="y", label="text") == "x: ['x'], y: ['y'], ls: x, w: xyz, label: text") +@pytest.mark.parametrize('func', all_funcs, ids=all_func_ids) +def test_function_call_with_dict_input(func): + """Tests with dict input, unpacking via preprocess_pipeline""" + data = {'a': 1, 'b': 2} + assert(func(None, data.keys(), data.values()) == + "x: ['a', 'b'], y: [1, 2], ls: x, w: xyz, label: None") + @pytest.mark.parametrize('func', all_funcs, ids=all_func_ids) def test_function_call_with_dict_data(func): """Test with dict data -> label comes from the value of 'x' parameter.""" - data = {"a": [1, 2], "b": [8, 9], "w": "NOT"} + data = {'a': [1, 2], 'b': [8, 9], "w": "NOT"} assert (func(None, "a", "b", data=data) == "x: [1, 2], y: [8, 9], ls: x, w: xyz, label: b") assert (func(None, x="a", y="b", data=data) == @@ -215,3 +223,29 @@ def funcy(ax, x, y, z, t=None): assert not re.search(r"every other argument", funcy.__doc__) assert not re.search(r"the following arguments .*: \*x\*, \*t\*\.", funcy.__doc__) + + +class TestPlotTypes: + plotters = [Axes.scatter, Axes.bar, Axes.plot] + + @pytest.mark.parametrize('plotter', plotters) + @check_figures_equal(extensions=['png']) + def test_dict_unpack(self, plotter, fig_test, fig_ref): + x = [1,2,3] + y = [4,5,6] + ddict = dict(zip(x,y)) + + plotter(fig_test.subplots(), + ddict.keys(), ddict.values()) + plotter(fig_ref.subplots(), x, y) + + @pytest.mark.parametrize('plotter', plotters) + @check_figures_equal(extensions=['png']) + def test_data_kwarg(self, plotter, fig_test, fig_ref): + x = [1,2,3] + y = [4,5,6] + + plotter(fig_test.subplots(), 'xval', 'yval', + data={'xval':x, 'yval':y}) + plotter(fig_ref.subplots(), x, y) + \ No newline at end of file From 2e20e67c68fda9e6bace5dc167f2c9f341ea16b8 Mon Sep 17 00:00:00 2001 From: hannah Date: Mon, 25 May 2020 04:59:02 -0400 Subject: [PATCH 2/5] closes #17502 by adding check to plot --- lib/matplotlib/axes/_base.py | 5 +++- lib/matplotlib/tests/test_preprocess_data.py | 25 ++++++++++---------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index 8852f12bfdd9..8b872bf1056e 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -217,7 +217,9 @@ def __call__(self, *args, data=None, **kwargs): if not args: return - if data is not None: # Process the 'data' kwarg. + if data is None: # Process dict views + args = [cbook.sanitize_sequence(a) for a in args] + else: # Process the 'data' kwarg. replaced = [mpl._replacer(data, arg) for arg in args] if len(args) == 1: label_namer_idx = 0 @@ -262,6 +264,7 @@ def __call__(self, *args, data=None, **kwargs): # Repeatedly grab (x, y) or (x, y, format) from the front of args and # massage them into arguments to plot() or fill(). + while args: this, args = args[:2], args[2:] if args and isinstance(args[0], str): diff --git a/lib/matplotlib/tests/test_preprocess_data.py b/lib/matplotlib/tests/test_preprocess_data.py index 4f1fc670fb94..89644c69ab4a 100644 --- a/lib/matplotlib/tests/test_preprocess_data.py +++ b/lib/matplotlib/tests/test_preprocess_data.py @@ -73,12 +73,13 @@ def test_function_call_without_data(func): assert (func(None, x="x", y="y", label="text") == "x: ['x'], y: ['y'], ls: x, w: xyz, label: text") + @pytest.mark.parametrize('func', all_funcs, ids=all_func_ids) def test_function_call_with_dict_input(func): """Tests with dict input, unpacking via preprocess_pipeline""" - data = {'a': 1, 'b': 2} + data = {'a': 1, 'b': 2} assert(func(None, data.keys(), data.values()) == - "x: ['a', 'b'], y: [1, 2], ls: x, w: xyz, label: None") + "x: ['a', 'b'], y: [1, 2], ls: x, w: xyz, label: None") @pytest.mark.parametrize('func', all_funcs, ids=all_func_ids) @@ -227,25 +228,23 @@ def funcy(ax, x, y, z, t=None): class TestPlotTypes: plotters = [Axes.scatter, Axes.bar, Axes.plot] - @pytest.mark.parametrize('plotter', plotters) @check_figures_equal(extensions=['png']) def test_dict_unpack(self, plotter, fig_test, fig_ref): - x = [1,2,3] - y = [4,5,6] - ddict = dict(zip(x,y)) + x = [1, 2, 3] + y = [4, 5, 6] + ddict = dict(zip(x, y)) - plotter(fig_test.subplots(), + plotter(fig_test.subplots(), ddict.keys(), ddict.values()) plotter(fig_ref.subplots(), x, y) @pytest.mark.parametrize('plotter', plotters) @check_figures_equal(extensions=['png']) def test_data_kwarg(self, plotter, fig_test, fig_ref): - x = [1,2,3] - y = [4,5,6] + x = [1, 2, 3] + y = [4, 5, 6] - plotter(fig_test.subplots(), 'xval', 'yval', - data={'xval':x, 'yval':y}) - plotter(fig_ref.subplots(), x, y) - \ No newline at end of file + plotter(fig_test.subplots(), 'xval', 'yval', + data={'xval': x, 'yval': y}) + plotter(fig_ref.subplots(), x, y) \ No newline at end of file From 6a2d4980e0f0eca8998d6ae797a39c72e11643c1 Mon Sep 17 00:00:00 2001 From: hannah Date: Mon, 25 May 2020 05:24:03 -0400 Subject: [PATCH 3/5] flake --- lib/matplotlib/tests/test_preprocess_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_preprocess_data.py b/lib/matplotlib/tests/test_preprocess_data.py index 89644c69ab4a..617be0132074 100644 --- a/lib/matplotlib/tests/test_preprocess_data.py +++ b/lib/matplotlib/tests/test_preprocess_data.py @@ -247,4 +247,4 @@ def test_data_kwarg(self, plotter, fig_test, fig_ref): plotter(fig_test.subplots(), 'xval', 'yval', data={'xval': x, 'yval': y}) - plotter(fig_ref.subplots(), x, y) \ No newline at end of file + plotter(fig_ref.subplots(), x, y) From 81c01b29ee6c8baa1a3bf49f1754ea920006554a Mon Sep 17 00:00:00 2001 From: hannah Date: Mon, 25 May 2020 05:29:04 -0400 Subject: [PATCH 4/5] more flake, will rebase eventually probably --- lib/matplotlib/tests/test_preprocess_data.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/matplotlib/tests/test_preprocess_data.py b/lib/matplotlib/tests/test_preprocess_data.py index 617be0132074..acbd2eafc26e 100644 --- a/lib/matplotlib/tests/test_preprocess_data.py +++ b/lib/matplotlib/tests/test_preprocess_data.py @@ -227,7 +227,9 @@ def funcy(ax, x, y, z, t=None): class TestPlotTypes: + plotters = [Axes.scatter, Axes.bar, Axes.plot] + @pytest.mark.parametrize('plotter', plotters) @check_figures_equal(extensions=['png']) def test_dict_unpack(self, plotter, fig_test, fig_ref): From 58a59ed86116619840e05452299dad033beff977 Mon Sep 17 00:00:00 2001 From: hannah Date: Mon, 25 May 2020 11:02:37 -0400 Subject: [PATCH 5/5] reverted double quotes on string --- lib/matplotlib/tests/test_preprocess_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/tests/test_preprocess_data.py b/lib/matplotlib/tests/test_preprocess_data.py index acbd2eafc26e..1f4707679508 100644 --- a/lib/matplotlib/tests/test_preprocess_data.py +++ b/lib/matplotlib/tests/test_preprocess_data.py @@ -85,7 +85,7 @@ def test_function_call_with_dict_input(func): @pytest.mark.parametrize('func', all_funcs, ids=all_func_ids) def test_function_call_with_dict_data(func): """Test with dict data -> label comes from the value of 'x' parameter.""" - data = {'a': [1, 2], 'b': [8, 9], "w": "NOT"} + data = {"a": [1, 2], "b": [8, 9], "w": "NOT"} assert (func(None, "a", "b", data=data) == "x: [1, 2], y: [8, 9], ls: x, w: xyz, label: b") assert (func(None, x="a", y="b", data=data) ==