Skip to content

Commit 17cfac2

Browse files
TST: Verify functioning of histtype argument (GH23992)
1 parent 54fa3da commit 17cfac2

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

pandas/tests/plotting/test_hist_method.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ def test_plot_fails_when_ax_differs_from_figure(self):
129129
with pytest.raises(AssertionError):
130130
self.ts.hist(ax=ax1, figure=fig2)
131131

132+
@pytest.mark.parametrize(
133+
"histtype, expected, agg_func",
134+
[
135+
("bar", True, all),
136+
("barstacked", True, all),
137+
("step", False, any),
138+
("stepfilled", True, all),
139+
],
140+
)
141+
def test_histtype_argument(self, histtype, expected, agg_func):
142+
# GH23992 Verify functioning of histtype argument
143+
ser = Series(np.random.randint(1, 10))
144+
ax = ser.hist(bins=12, histtype=histtype)
145+
146+
result = agg_func(patch.fill for patch in ax.patches)
147+
assert result == expected
148+
132149
@pytest.mark.parametrize(
133150
"by, expected_axes_num, expected_layout", [(None, 1, (1, 1)), ("b", 2, (1, 2))]
134151
)
@@ -365,6 +382,23 @@ def test_hist_column_order_unchanged(self, column, expected):
365382

366383
assert result == expected
367384

385+
@pytest.mark.parametrize(
386+
"histtype, expected, agg_func",
387+
[
388+
("bar", True, all),
389+
("barstacked", True, all),
390+
("step", False, any),
391+
("stepfilled", True, all),
392+
],
393+
)
394+
def test_histtype_argument(self, histtype, expected, agg_func):
395+
# GH23992 Verify functioning of histtype argument
396+
df = DataFrame(np.random.randint(1, 10, size=(100, 2)), columns=["a", "b"])
397+
ax = df.hist(bins=12, histtype=histtype, layout=(-1, 1))
398+
399+
result = agg_func(patch.fill for row in ax for patch in row[0].patches)
400+
assert result == expected
401+
368402
@pytest.mark.parametrize("by", [None, "c"])
369403
@pytest.mark.parametrize("column", [None, "b"])
370404
def test_hist_with_legend(self, by, column):
@@ -595,3 +629,22 @@ def test_axis_share_xy(self):
595629

596630
assert ax1._shared_y_axes.joined(ax1, ax2)
597631
assert ax2._shared_y_axes.joined(ax1, ax2)
632+
633+
@pytest.mark.parametrize(
634+
"histtype, expected, agg_func",
635+
[
636+
("bar", True, all),
637+
("barstacked", True, all),
638+
("step", False, any),
639+
("stepfilled", True, all),
640+
],
641+
)
642+
def test_histtype_argument(self, histtype, expected, agg_func):
643+
# GH23992 Verify functioning of histtype argument
644+
df = DataFrame(
645+
np.random.randint(1, 10, size=(100, 2)), columns=["a", "b"]
646+
).groupby("a")
647+
ax = df.hist(bins=12, histtype=histtype, layout=(-1, 1))
648+
649+
result = agg_func(patch.fill for rows in ax for patch in rows[0][0].patches)
650+
assert result == expected

0 commit comments

Comments
 (0)