Skip to content

Commit a803b7c

Browse files
authored
TST: adding a test for bar plot with intervalrange xaxis (#47344)
* adding a test for bar plot with intervalrange xaxis * fixed assert in test * moved import to top * Revert "moved import to top" This reverts commit db9401b.
1 parent 9c241fe commit a803b7c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pandas/tests/plotting/test_misc.py

+17
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
Index,
1111
Series,
1212
Timestamp,
13+
interval_range,
1314
)
1415
import pandas._testing as tm
1516
from pandas.tests.plotting.common import (
@@ -597,3 +598,19 @@ def test_plot_bar_axis_units_timestamp_conversion(self):
597598
_check_plot_works(df.plot)
598599
s = Series({"A": 1.0})
599600
_check_plot_works(s.plot.bar)
601+
602+
def test_bar_plt_xaxis_intervalrange(self):
603+
# GH 38969
604+
# Ensure IntervalIndex x-axis produces a bar plot as expected
605+
from matplotlib.text import Text
606+
607+
expected = [Text(0, 0, "([0, 1],)"), Text(1, 0, "([1, 2],)")]
608+
s = Series(
609+
[1, 2],
610+
index=[interval_range(0, 2)],
611+
)
612+
_check_plot_works(s.plot.bar)
613+
assert all(
614+
(a.get_text() == b.get_text())
615+
for a, b in zip(s.plot.bar().get_xticklabels(), expected)
616+
)

0 commit comments

Comments
 (0)