From a063f23264481cb409387ca1d7eb049c9054ff54 Mon Sep 17 00:00:00 2001 From: Sabrina Date: Mon, 11 Oct 2021 12:47:11 -0300 Subject: [PATCH 1/3] creating function to test bar plot index --- pandas/tests/plotting/test_misc.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index adda95f4c5aa0..867153ece1cfa 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -2,12 +2,13 @@ import numpy as np import pytest +from matplotlib.text import Text import pandas.util._test_decorators as td from pandas import ( DataFrame, - Series, + Series, Index, ) import pandas._testing as tm from pandas.tests.plotting.common import ( @@ -450,6 +451,25 @@ 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): + # issue-38947 + # Test bar plot with string index + + 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.__eq__(b) for a, b in zip(plot_bar.get_xticklabels(), expected)]) + except TypeError as e: + assert False + def test_has_externally_shared_axis_x_axis(self): # GH33819 # Test _has_externally_shared_axis() works for x-axis From f3d74be16ee65ea043a989ab5a4ae33290ae8fce Mon Sep 17 00:00:00 2001 From: Sabrina Date: Thu, 14 Oct 2021 17:11:39 -0300 Subject: [PATCH 2/3] correcting == --- pandas/tests/plotting/test_misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index 867153ece1cfa..3959db0ebd47c 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -466,7 +466,7 @@ def test_bar_plot(self): try: plot_bar = df.plot.bar() - assert all([a.__eq__(b) for a, b in zip(plot_bar.get_xticklabels(), expected)]) + assert all([(a.get_text() == b.get_text()) for a, b in zip(plot_bar.get_xticklabels(), expected)]) except TypeError as e: assert False From a1cd451a0f01335e859773c4d6c9f420567b8d8d Mon Sep 17 00:00:00 2001 From: Sabrina Date: Thu, 14 Oct 2021 17:20:37 -0300 Subject: [PATCH 3/3] shortening line --- pandas/tests/plotting/test_misc.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index 3959db0ebd47c..c9cd212696a56 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -466,7 +466,8 @@ def test_bar_plot(self): try: plot_bar = df.plot.bar() - assert all([(a.get_text() == b.get_text()) for a, b in zip(plot_bar.get_xticklabels(), expected)]) + assert all([(a.get_text() == b.get_text()) + for a, b in zip(plot_bar.get_xticklabels(), expected)]) except TypeError as e: assert False