From 467f699ba1bf51afa36bf17d86a914abc4b5d220 Mon Sep 17 00:00:00 2001 From: Avinash Pancham Date: Sat, 30 Jan 2021 21:14:48 +0100 Subject: [PATCH 1/2] TST: Verify plot order of a Series (GH38865) --- pandas/tests/plotting/test_series.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 9cd13b2312ea7..306e55ead0bfd 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -752,6 +752,18 @@ def test_plot_no_numeric_data(self): with pytest.raises(TypeError, match="no numeric data to plot"): df.plot() + def test_plot_order(self): + # GH38865 Verify plot order of a Series + ser = Series(data=[1, 2, 3, 4], index=[3, 2, 1, 0]) + ax = ser.plot(kind="bar") + + expected = ser.tolist() + result = [ + patch.get_bbox().ymax + for patch in sorted(ax.patches, key=lambda patch: patch.get_bbox().xmax) + ] + assert expected == result + def test_style_single_ok(self): s = Series([1, 2]) ax = s.plot(style="s", color="C3") From 2e12c7f8faacb0e91e96d59936b351fd74527735 Mon Sep 17 00:00:00 2001 From: Avinash Pancham Date: Sat, 30 Jan 2021 21:49:21 +0100 Subject: [PATCH 2/2] Parametrize test --- pandas/tests/plotting/test_series.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 306e55ead0bfd..b4848f80e9a2c 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -752,9 +752,16 @@ def test_plot_no_numeric_data(self): with pytest.raises(TypeError, match="no numeric data to plot"): df.plot() - def test_plot_order(self): + @pytest.mark.parametrize( + "data, index", + [ + ([1, 2, 3, 4], [3, 2, 1, 0]), + ([10, 50, 20, 30], [1910, 1920, 1980, 1950]), + ], + ) + def test_plot_order(self, data, index): # GH38865 Verify plot order of a Series - ser = Series(data=[1, 2, 3, 4], index=[3, 2, 1, 0]) + ser = Series(data=data, index=index) ax = ser.plot(kind="bar") expected = ser.tolist()