Skip to content

Commit 11cc850

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

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
@@ -1,12 +1,14 @@
11
""" Test cases for misc plot functions """
22

3+
from matplotlib.text import Text
34
import numpy as np
45
import pytest
56

67
import pandas.util._test_decorators as td
78

89
from pandas import (
910
DataFrame,
11+
Index,
1012
Series,
1113
Timestamp,
1214
)
@@ -441,6 +443,28 @@ def test_dictionary_color(self):
441443
colors = [rect.get_color() for rect in ax.get_lines()[0:2]]
442444
assert all(color == expected[index] for index, color in enumerate(colors))
443445

446+
def test_bar_plot(self):
447+
# issue-38947
448+
# Test bar plot with string index
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)