Skip to content

TST: Verify functioning of histtype argument (GH23992) #37063

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 13 commits into from
Nov 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 21 additions & 0 deletions pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,27 @@ def _check_visible(self, collections, visible=True):
for patch in collections:
assert patch.get_visible() == visible

def _check_filled(self, ax, filled=True):
Copy link
Member

Choose a reason for hiding this comment

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

i would suggest to rename it, since _check_filled sounds a bit vague to me

also would be nice to annotate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated name to _check_filling.

What do you mean with annotate, since the function already has a docstring.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry my bad, I was bit confused wrt to annotation. Added annotation to all new functions

Copy link
Member

@charlesdong1991 charlesdong1991 Oct 29, 2020

Choose a reason for hiding this comment

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

emm, i meant to give it a more meaningful name than _check_filling, maybe use _check_patches_all_filled or _check_artists_all_filled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to _check_patches_all_filled

"""
Check each artist is filled or not

Parameters
----------
ax : matplotlib Axes object or a numpy.ndarray of them
filled : bool
expected filling
"""

def _check_patch_filling(artist):
for patch in artist.patches:
assert patch.fill == filled

if isinstance(ax, np.ndarray):
for rows in ax.flatten():
_check_patch_filling(rows)
else:
_check_patch_filling(ax)

def _get_colors_mapped(self, series, colors):
unique = series.unique()
# unique and colors length can be differed
Expand Down
45 changes: 45 additions & 0 deletions pandas/tests/plotting/test_hist_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,21 @@ def test_plot_fails_when_ax_differs_from_figure(self):
with pytest.raises(AssertionError):
self.ts.hist(ax=ax1, figure=fig2)

@pytest.mark.parametrize(
"histtype, expected",
[
("bar", True),
("barstacked", True),
("step", False),
("stepfilled", True),
],
)
def test_histtype_argument(self, histtype, expected):
# GH23992 Verify functioning of histtype argument
ser = Series(np.random.randint(1, 10))
ax = ser.hist(histtype=histtype)
self._check_filled(ax, filled=expected)

@pytest.mark.parametrize(
"by, expected_axes_num, expected_layout", [(None, 1, (1, 1)), ("b", 2, (1, 2))]
)
Expand Down Expand Up @@ -365,6 +380,21 @@ def test_hist_column_order_unchanged(self, column, expected):

assert result == expected

@pytest.mark.parametrize(
"histtype, expected",
[
("bar", True),
("barstacked", True),
("step", False),
("stepfilled", True),
],
)
def test_histtype_argument(self, histtype, expected):
# GH23992 Verify functioning of histtype argument
df = DataFrame(np.random.randint(1, 10, size=(100, 2)), columns=["a", "b"])
ax = df.hist(histtype=histtype)
self._check_filled(ax, filled=expected)

@pytest.mark.parametrize("by", [None, "c"])
@pytest.mark.parametrize("column", [None, "b"])
def test_hist_with_legend(self, by, column):
Expand Down Expand Up @@ -595,3 +625,18 @@ def test_axis_share_xy(self):

assert ax1._shared_y_axes.joined(ax1, ax2)
assert ax2._shared_y_axes.joined(ax1, ax2)

@pytest.mark.parametrize(
"histtype, expected",
[
("bar", True),
("barstacked", True),
("step", False),
("stepfilled", True),
],
)
def test_histtype_argument(self, histtype, expected):
# GH23992 Verify functioning of histtype argument
df = DataFrame(np.random.randint(1, 10, size=(100, 2)), columns=["a", "b"])
ax = df.hist(by="a", histtype=histtype)
self._check_filled(ax, filled=expected)