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 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
22 changes: 22 additions & 0 deletions pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from typing import TYPE_CHECKING, Sequence, Union
import warnings

import numpy as np
Expand All @@ -12,6 +13,9 @@
from pandas import DataFrame, Series, to_datetime
import pandas._testing as tm

if TYPE_CHECKING:
from matplotlib.axes import Axes


@td.skip_if_no_mpl
class TestPlotBase:
Expand Down Expand Up @@ -172,6 +176,24 @@ def _check_visible(self, collections, visible=True):
for patch in collections:
assert patch.get_visible() == visible

def _check_patches_all_filled(
self, axes: Union["Axes", Sequence["Axes"]], filled: bool = True
) -> None:
"""
Check for each artist whether it is filled or not

Parameters
----------
axes : matplotlib Axes object, or its list-like
filled : bool
expected filling
"""

axes = self._flatten_visible(axes)
for ax in axes:
for patch in ax.patches:
assert patch.fill == filled

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 @@ -128,6 +128,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_patches_all_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 @@ -364,6 +379,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_patches_all_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 @@ -594,3 +624,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_patches_all_filled(ax, filled=expected)