From 67653393c78add51059412869a2119a23f85a244 Mon Sep 17 00:00:00 2001 From: Vinicius Akira Imaizumi Date: Sun, 20 Mar 2022 23:42:22 +0100 Subject: [PATCH 1/2] TST: GH38947 creating function to test bar plot index --- pandas/tests/plotting/test_misc.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index 656590cdb02be..e7637ad93c188 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -7,6 +7,7 @@ from pandas import ( DataFrame, + Index, Series, Timestamp, ) @@ -441,6 +442,29 @@ def test_dictionary_color(self): colors = [rect.get_color() for rect in ax.get_lines()[0:2]] assert all(color == expected[index] for index, color in enumerate(colors)) + def test_bar_plot(self): + # GH38947 + # Test bar plot with string and int index + from matplotlib.text import Text + + expected = [Text(0, 0, "0"), Text(1, 0, "Total")] + + df = DataFrame( + { + "a": [1, 2], + }, + index=Index([0, "Total"]), + ) + + try: + plot_bar = df.plot.bar() + assert all( + (a.get_text() == b.get_text()) + for a, b in zip(plot_bar.get_xticklabels(), expected) + ) + except TypeError: + assert False + def test_has_externally_shared_axis_x_axis(self): # GH33819 # Test _has_externally_shared_axis() works for x-axis From a0bc4f697973ff66e709886b200290f6f082aaaf Mon Sep 17 00:00:00 2001 From: Vinicius Akira Imaizumi Date: Sun, 24 Apr 2022 12:41:23 +0200 Subject: [PATCH 2/2] TST: GH38947 removing try/except since assert will raise appropriately --- pandas/tests/plotting/test_misc.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index e7637ad93c188..9c7996adfed38 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -455,15 +455,11 @@ def test_bar_plot(self): }, index=Index([0, "Total"]), ) - - try: - plot_bar = df.plot.bar() - assert all( - (a.get_text() == b.get_text()) - for a, b in zip(plot_bar.get_xticklabels(), expected) - ) - except TypeError: - assert False + plot_bar = df.plot.bar() + assert all( + (a.get_text() == b.get_text()) + for a, b in zip(plot_bar.get_xticklabels(), expected) + ) def test_has_externally_shared_axis_x_axis(self): # GH33819