Skip to content

Commit 61693c6

Browse files
committed
Requested changes
1 parent e0c9466 commit 61693c6

File tree

3 files changed

+56
-32
lines changed

3 files changed

+56
-32
lines changed

pandas/plotting/_core.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import importlib
2+
from typing import TYPE_CHECKING, Optional, Sequence, Tuple, Union
23

34
from pandas._config import get_option
45

@@ -9,20 +10,23 @@
910

1011
from pandas.core.base import PandasObject
1112

13+
if TYPE_CHECKING:
14+
from pandas import DataFrame
15+
1216

1317
def hist_series(
1418
self,
1519
by=None,
1620
ax=None,
17-
grid=True,
18-
xlabelsize=None,
19-
xrot=None,
20-
ylabelsize=None,
21-
yrot=None,
22-
figsize=None,
23-
bins=10,
24-
legend=False,
25-
backend=None,
21+
grid: bool = True,
22+
xlabelsize: Optional[int] = None,
23+
xrot: Optional[float] = None,
24+
ylabelsize: Optional[int] = None,
25+
yrot: Optional[float] = None,
26+
figsize: Optional[Tuple[int, int]] = None,
27+
bins: Union[int, Sequence[int]] = 10,
28+
legend: bool = False,
29+
backend: Optional[str] = None,
2630
**kwargs,
2731
):
2832
"""
@@ -53,6 +57,9 @@ def hist_series(
5357
bin. In this case, bins is returned unmodified.
5458
legend : bool, default False
5559
Whether to show the legend.
60+
61+
..versionadded:: 1.1.0
62+
5663
backend : str, default None
5764
Backend to use instead of the backend specified in the option
5865
``plotting.backend``. For instance, 'matplotlib'. Alternatively, to
@@ -91,22 +98,22 @@ def hist_series(
9198

9299

93100
def hist_frame(
94-
data,
95-
column=None,
101+
data: "DataFrame",
102+
column: Optional[Union[str, Sequence[str]]] = None,
96103
by=None,
97-
grid=True,
98-
xlabelsize=None,
99-
xrot=None,
100-
ylabelsize=None,
101-
yrot=None,
104+
grid: bool = True,
105+
xlabelsize: Optional[int] = None,
106+
xrot: Optional[float] = None,
107+
ylabelsize: Optional[int] = None,
108+
yrot: Optional[float] = None,
102109
ax=None,
103-
sharex=False,
104-
sharey=False,
105-
figsize=None,
106-
layout=None,
107-
bins=10,
108-
legend=False,
109-
backend=None,
110+
sharex: bool = False,
111+
sharey: bool = False,
112+
figsize: Optional[Tuple[int, int]] = None,
113+
layout: Optional[Tuple[int, int]] = None,
114+
bins: Union[int, Sequence[int]] = 10,
115+
legend: bool = False,
116+
backend: Optional[str] = None,
110117
**kwargs,
111118
):
112119
"""
@@ -161,6 +168,9 @@ def hist_frame(
161168
bin. In this case, bins is returned unmodified.
162169
legend : bool, default False
163170
Whether to show the legend.
171+
172+
..versionadded:: 1.1.0
173+
164174
backend : str, default None
165175
Backend to use instead of the backend specified in the option
166176
``plotting.backend``. For instance, 'matplotlib'. Alternatively, to

pandas/tests/plotting/test_groupby.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from pandas import DataFrame, Index, Series
1010
import pandas._testing as tm
11-
from pandas.tests.plotting.common import TestPlotBase, _check_plot_works
11+
from pandas.tests.plotting.common import TestPlotBase
1212

1313

1414
@td.skip_if_no_mpl
@@ -70,6 +70,8 @@ def test_plot_kwargs(self):
7070
@pytest.mark.parametrize("column, expected_axes_num", [(None, 2), ("b", 1)])
7171
@pytest.mark.parametrize("label", [None, "d"])
7272
def test_groupby_hist_with_legend(self, column, expected_axes_num, label):
73+
# GH 6279
74+
# Histogram can have a legend
7375
expected_layout = (1, expected_axes_num)
7476
expected_labels = label or column or [["a"], ["b"]]
7577

@@ -84,13 +86,19 @@ def test_groupby_hist_with_legend(self, column, expected_axes_num, label):
8486

8587
ret = g.hist(**kwargs)
8688
for (_, axes) in ret.iteritems():
87-
self._check_axes_shape(axes, axes_num=expected_axes_num, layout=expected_layout)
89+
self._check_axes_shape(
90+
axes, axes_num=expected_axes_num, layout=expected_layout
91+
)
8892
for ax, expected_label in zip(axes[0], expected_labels):
8993
self._check_legend_labels(ax, expected_label)
9094
tm.close()
9195

92-
@pytest.mark.parametrize("label, expected_label", [(None, ['1', '2']), ("d", ["d", "d"])])
96+
@pytest.mark.parametrize(
97+
"label, expected_label", [(None, ["1", "2"]), ("d", ["d", "d"])]
98+
)
9399
def test_groupby_hist_series_with_legend(self, label, expected_label):
100+
# GH 6279
101+
# Histogram can have a legend
94102
index = Index(15 * [1] + 15 * [2], name="c")
95103
df = DataFrame(np.random.randn(30, 2), index=index, columns=["a", "b"])
96104
g = df.groupby("c")

pandas/tests/plotting/test_hist_method.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,22 @@ 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.slow
133-
@pytest.mark.parametrize("by, expected_axes_num, expected_layout", [(None, 1, (1, 1)), ("b", 2, (1, 2))])
132+
@pytest.mark.parametrize(
133+
"by, expected_axes_num, expected_layout", [(None, 1, (1, 1)), ("b", 2, (1, 2))]
134+
)
134135
@pytest.mark.parametrize("label, expected_label", [(None, "a"), ("c", "c")])
135-
def test_hist_with_legend(self, by, expected_axes_num, expected_layout, label, expected_label):
136+
def test_hist_with_legend(
137+
self, by, expected_axes_num, expected_layout, label, expected_label
138+
):
139+
# GH 6279
140+
# Histogram can have a legend
136141
index = 15 * [1] + 15 * [2]
137142
s = Series(np.random.randn(30), index=index, name="a")
138143
s.index.name = "b"
139144

140145
kwargs = {"legend": True, "by": by}
146+
# We get warnings if kwargs contains "label": None
141147
if label is not None:
142-
# Behavior differs if kwargs contains "label": None
143148
kwargs["label"] = label
144149

145150
axes = _check_plot_works(s.hist, **kwargs)
@@ -310,11 +315,12 @@ def test_hist_column_order_unchanged(self, column, expected):
310315

311316
assert result == expected
312317

313-
@pytest.mark.slow
314318
@pytest.mark.parametrize("by", [None, "c"])
315319
@pytest.mark.parametrize("column", [None, "b"])
316320
@pytest.mark.parametrize("label", [None, "d"])
317321
def test_hist_with_legend(self, by, column, label):
322+
# GH 6279
323+
# Histogram can have a legend
318324
expected_axes_num = 1 if by is None and column is not None else 2
319325
expected_layout = (1, expected_axes_num)
320326
expected_labels = label or column or ["a", "b"]
@@ -325,8 +331,8 @@ def test_hist_with_legend(self, by, column, label):
325331
df = DataFrame(np.random.randn(30, 2), index=index, columns=["a", "b"])
326332

327333
kwargs = {"legend": True, "by": by, "column": column}
334+
# We get warnings if kwargs contains "label": None
328335
if label is not None:
329-
# Behavior differs if kwargs contains "label": None
330336
kwargs["label"] = label
331337

332338
axes = _check_plot_works(df.hist, **kwargs)

0 commit comments

Comments
 (0)