diff --git a/pandas/tests/plotting/common.py b/pandas/tests/plotting/common.py index c04b70f3c2953..82a62c4588b94 100644 --- a/pandas/tests/plotting/common.py +++ b/pandas/tests/plotting/common.py @@ -1,4 +1,5 @@ import os +from typing import TYPE_CHECKING, Sequence, Union import warnings import numpy as np @@ -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: @@ -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 diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 9775218e0dbf6..49335230171c6 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -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))] ) @@ -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): @@ -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)