Skip to content

Commit 48865f4

Browse files
committed
TYP: plotting
1 parent eaf911f commit 48865f4

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

pandas/plotting/_matplotlib/boxplot.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,18 @@ def __init__(self, data, return_type: str = "axes", **kwargs) -> None:
9393
# error: Signature of "_plot" incompatible with supertype "MPLPlot"
9494
@classmethod
9595
def _plot( # type: ignore[override]
96-
cls, ax: Axes, y, column_num=None, return_type: str = "axes", **kwds
96+
cls, ax: Axes, y: np.ndarray, column_num=None, return_type: str = "axes", **kwds
9797
):
98+
ys: np.ndarray | list[np.ndarray]
9899
if y.ndim == 2:
99-
y = [remove_na_arraylike(v) for v in y]
100+
ys = [remove_na_arraylike(v) for v in y]
100101
# Boxplot fails with empty arrays, so need to add a NaN
101102
# if any cols are empty
102103
# GH 8181
103-
y = [v if v.size > 0 else np.array([np.nan]) for v in y]
104+
ys = [v if v.size > 0 else np.array([np.nan]) for v in ys]
104105
else:
105-
y = remove_na_arraylike(y)
106-
bp = ax.boxplot(y, **kwds)
106+
ys = remove_na_arraylike(y)
107+
bp = ax.boxplot(ys, **kwds)
107108

108109
if return_type == "dict":
109110
return bp, bp

pandas/plotting/_matplotlib/core.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,14 @@ def _make_plot(self, fig: Figure) -> None:
14481448
# error: Signature of "_plot" incompatible with supertype "MPLPlot"
14491449
@classmethod
14501450
def _plot( # type: ignore[override]
1451-
cls, ax: Axes, x, y, style=None, column_num=None, stacking_id=None, **kwds
1451+
cls,
1452+
ax: Axes,
1453+
x,
1454+
y: np.ndarray,
1455+
style=None,
1456+
column_num=None,
1457+
stacking_id=None,
1458+
**kwds,
14521459
):
14531460
# column_num is used to get the target column from plotf in line and
14541461
# area plots
@@ -1475,7 +1482,7 @@ def _ts_plot(self, ax: Axes, x, data: Series, style=None, **kwds):
14751482
decorate_axes(ax.right_ax, freq, kwds)
14761483
ax._plot_data.append((data, self._kind, kwds))
14771484

1478-
lines = self._plot(ax, data.index, data.values, style=style, **kwds)
1485+
lines = self._plot(ax, data.index, np.asarray(data.values), style=style, **kwds)
14791486
# set date formatter, locators and rescale limits
14801487
# error: Argument 3 to "format_dateaxis" has incompatible type "Index";
14811488
# expected "DatetimeIndex | PeriodIndex"
@@ -1503,7 +1510,9 @@ def _initialize_stacker(cls, ax: Axes, stacking_id, n: int) -> None:
15031510

15041511
@final
15051512
@classmethod
1506-
def _get_stacked_values(cls, ax: Axes, stacking_id, values, label):
1513+
def _get_stacked_values(
1514+
cls, ax: Axes, stacking_id: int | None, values: np.ndarray, label
1515+
) -> np.ndarray:
15071516
if stacking_id is None:
15081517
return values
15091518
if not hasattr(ax, "_stacker_pos_prior"):
@@ -1523,7 +1532,7 @@ def _get_stacked_values(cls, ax: Axes, stacking_id, values, label):
15231532

15241533
@final
15251534
@classmethod
1526-
def _update_stacker(cls, ax: Axes, stacking_id, values) -> None:
1535+
def _update_stacker(cls, ax: Axes, stacking_id: int | None, values) -> None:
15271536
if stacking_id is None:
15281537
return
15291538
if (values >= 0).all():
@@ -1601,7 +1610,7 @@ def _plot( # type: ignore[override]
16011610
cls,
16021611
ax: Axes,
16031612
x,
1604-
y,
1613+
y: np.ndarray,
16051614
style=None,
16061615
column_num=None,
16071616
stacking_id=None,
@@ -1727,7 +1736,7 @@ def _plot( # type: ignore[override]
17271736
cls,
17281737
ax: Axes,
17291738
x,
1730-
y,
1739+
y: np.ndarray,
17311740
w,
17321741
start: int | npt.NDArray[np.intp] = 0,
17331742
log: bool = False,
@@ -1860,7 +1869,7 @@ def _plot( # type: ignore[override]
18601869
cls,
18611870
ax: Axes,
18621871
x,
1863-
y,
1872+
y: np.ndarray,
18641873
w,
18651874
start: int | npt.NDArray[np.intp] = 0,
18661875
log: bool = False,

pandas/plotting/_matplotlib/hist.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def _calculate_bins(self, data: DataFrame, bins) -> np.ndarray:
101101
def _plot( # type: ignore[override]
102102
cls,
103103
ax: Axes,
104-
y,
104+
y: np.ndarray,
105105
style=None,
106106
bottom: int | np.ndarray = 0,
107107
column_num: int = 0,
@@ -166,7 +166,7 @@ def _make_plot(self, fig: Figure) -> None:
166166

167167
self._append_legend_handles_labels(artists[0], label)
168168

169-
def _make_plot_keywords(self, kwds: dict[str, Any], y) -> None:
169+
def _make_plot_keywords(self, kwds: dict[str, Any], y: np.ndarray) -> None:
170170
"""merge BoxPlot/KdePlot properties to passed kwds"""
171171
# y is required for KdePlot
172172
kwds["bottom"] = self.bottom
@@ -225,7 +225,7 @@ def __init__(
225225
self.weights = weights
226226

227227
@staticmethod
228-
def _get_ind(y, ind):
228+
def _get_ind(y: np.ndarray, ind):
229229
if ind is None:
230230
# np.nanmax() and np.nanmin() ignores the missing values
231231
sample_range = np.nanmax(y) - np.nanmin(y)
@@ -248,12 +248,12 @@ def _get_ind(y, ind):
248248
def _plot( # type: ignore[override]
249249
cls,
250250
ax: Axes,
251-
y,
251+
y: np.ndarray,
252252
style=None,
253253
bw_method=None,
254254
ind=None,
255255
column_num=None,
256-
stacking_id=None,
256+
stacking_id: int | None = None,
257257
**kwds,
258258
):
259259
from scipy.stats import gaussian_kde
@@ -265,7 +265,7 @@ def _plot( # type: ignore[override]
265265
lines = MPLPlot._plot(ax, ind, y, style=style, **kwds)
266266
return lines
267267

268-
def _make_plot_keywords(self, kwds: dict[str, Any], y) -> None:
268+
def _make_plot_keywords(self, kwds: dict[str, Any], y: np.ndarray) -> None:
269269
kwds["bw_method"] = self.bw_method
270270
kwds["ind"] = self._get_ind(y, ind=self.ind)
271271

0 commit comments

Comments
 (0)