Skip to content

TST: adding a test for bar plot with intervalrange xaxis #47344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pandas/tests/plotting/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Index,
Series,
Timestamp,
interval_range,
)
import pandas._testing as tm
from pandas.tests.plotting.common import (
Expand Down Expand Up @@ -597,3 +598,19 @@ def test_plot_bar_axis_units_timestamp_conversion(self):
_check_plot_works(df.plot)
s = Series({"A": 1.0})
_check_plot_works(s.plot.bar)

def test_bar_plt_xaxis_intervalrange(self):
# GH 38969
# Ensure IntervalIndex x-axis produces a bar plot as expected
from matplotlib.text import Text
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We normally don't add these comments, when an issue is linked.

I don't know matplotlib very well, but can we import this at the top?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can. I will go ahead and clean it from the other 2 tests that import it.

Huh, do you mean the 2nd line comment? I noticed that most tests in this Misc file do this. But I really don't mind deleting it...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx.

Oh interesting. I am not really familiar with our plotting code-base. We try to avoid most comments in tests in other places. I think you can keep it in, if it is consistent with the rest though.


expected = [Text(0, 0, "([0, 1],)"), Text(1, 0, "([1, 2],)")]
s = Series(
[1, 2],
index=[interval_range(0, 2)],
)
_check_plot_works(s.plot.bar)
assert all(
(a.get_text() == b.get_text())
for a, b in zip(s.plot.bar().get_xticklabels(), expected)
)