Skip to content

Commit 6765339

Browse files
committed
TST: GH38947 creating function to test bar plot index
1 parent 6033ed4 commit 6765339

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

pandas/tests/plotting/test_misc.py

+24
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,29 @@ 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+
459+
try:
460+
plot_bar = df.plot.bar()
461+
assert all(
462+
(a.get_text() == b.get_text())
463+
for a, b in zip(plot_bar.get_xticklabels(), expected)
464+
)
465+
except TypeError:
466+
assert False
467+
444468
def test_has_externally_shared_axis_x_axis(self):
445469
# GH33819
446470
# Test _has_externally_shared_axis() works for x-axis

0 commit comments

Comments
 (0)