Skip to content

Commit 3f27fed

Browse files
Daquisuyehoshuadimarsky
authored andcommitted
TST: GH38947 creating function to test bar plot index (pandas-dev#46451)
* TST: GH38947 creating function to test bar plot index * TST: GH38947 removing try/except since assert will raise appropriately
1 parent 05ae872 commit 3f27fed

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pandas/tests/plotting/test_misc.py

+20
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from pandas import (
99
DataFrame,
10+
Index,
1011
Series,
1112
Timestamp,
1213
)
@@ -441,6 +442,25 @@ def test_dictionary_color(self):
441442
colors = [rect.get_color() for rect in ax.get_lines()[0:2]]
442443
assert all(color == expected[index] for index, color in enumerate(colors))
443444

445+
def test_bar_plot(self):
446+
# GH38947
447+
# Test bar plot with string and int index
448+
from matplotlib.text import Text
449+
450+
expected = [Text(0, 0, "0"), Text(1, 0, "Total")]
451+
452+
df = DataFrame(
453+
{
454+
"a": [1, 2],
455+
},
456+
index=Index([0, "Total"]),
457+
)
458+
plot_bar = df.plot.bar()
459+
assert all(
460+
(a.get_text() == b.get_text())
461+
for a, b in zip(plot_bar.get_xticklabels(), expected)
462+
)
463+
444464
def test_has_externally_shared_axis_x_axis(self):
445465
# GH33819
446466
# Test _has_externally_shared_axis() works for x-axis

0 commit comments

Comments
 (0)