diff --git a/pandas/plotting/_core.py b/pandas/plotting/_core.py index f16323e0337bf..c91903f7bd43e 100644 --- a/pandas/plotting/_core.py +++ b/pandas/plotting/_core.py @@ -962,7 +962,10 @@ def _get_call_args(backend_name: str, data: Series | DataFrame, args, kwargs): if args and isinstance(data, ABCSeries): positional_args = str(args)[1:-1] keyword_args = ", ".join( - [f"{name}={value!r}" for (name, _), value in zip(arg_def, args)] + [ + f"{name}={value!r}" + for (name, _), value in zip(arg_def, args, strict=False) + ] ) msg = ( "`Series.plot()` should not be called with positional " @@ -973,7 +976,9 @@ def _get_call_args(backend_name: str, data: Series | DataFrame, args, kwargs): ) raise TypeError(msg) - pos_args = {name: value for (name, _), value in zip(arg_def, args)} + pos_args = { + name: value for (name, _), value in zip(arg_def, args, strict=False) + } if backend_name == "pandas.plotting._matplotlib": kwargs = dict(arg_def, **pos_args, **kwargs) else: diff --git a/pandas/plotting/_matplotlib/boxplot.py b/pandas/plotting/_matplotlib/boxplot.py index 32b1fbe73a310..4bb185c51478f 100644 --- a/pandas/plotting/_matplotlib/boxplot.py +++ b/pandas/plotting/_matplotlib/boxplot.py @@ -321,9 +321,9 @@ def _grouped_plot_by_column( ax_values = [] - for ax, col in zip(flatten_axes(axes), columns): + for ax, col in zip(flatten_axes(axes), columns, strict=False): gp_col = grouped[col] - keys, values = zip(*gp_col) + keys, values = zip(*gp_col, strict=True) re_plotf = plotf(keys, values, ax, xlabel=xlabel, ylabel=ylabel, **kwargs) ax.set_title(col) ax_values.append(re_plotf) @@ -380,7 +380,7 @@ def _get_colors(): # taken from the colors dict parameter # "boxes" value placed in position 0, "whiskers" in 1, etc. valid_keys = ["boxes", "whiskers", "medians", "caps"] - key_to_index = dict(zip(valid_keys, range(4))) + key_to_index = dict(zip(valid_keys, range(4), strict=True)) for key, value in colors.items(): if key in valid_keys: result[key_to_index[key]] = value @@ -530,7 +530,7 @@ def boxplot_frame_groupby( layout=layout, ) data = {} - for (key, group), ax in zip(grouped, flatten_axes(axes)): + for (key, group), ax in zip(grouped, flatten_axes(axes), strict=False): d = group.boxplot( ax=ax, column=column, fontsize=fontsize, rot=rot, grid=grid, **kwds ) @@ -539,7 +539,7 @@ def boxplot_frame_groupby( ret = pd.Series(data) maybe_adjust_figure(fig, bottom=0.15, top=0.9, left=0.1, right=0.9, wspace=0.2) else: - keys, frames = zip(*grouped) + keys, frames = zip(*grouped, strict=True) df = pd.concat(frames, keys=keys, axis=1) # GH 16748, DataFrameGroupby fails when subplots=False and `column` argument diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index b0817a1b4a04e..b8f59363b5107 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -817,7 +817,7 @@ def _adorn_subplots(self, fig: Figure) -> None: f"number of columns = {self.nseries}" ) - for ax, title in zip(self.axes, self.title): + for ax, title in zip(self.axes, self.title, strict=False): ax.set_title(title) else: fig.suptitle(self.title) @@ -1216,7 +1216,7 @@ def _get_errorbars( ) -> dict[str, Any]: errors = {} - for kw, flag in zip(["xerr", "yerr"], [xerr, yerr]): + for kw, flag in zip(["xerr", "yerr"], [xerr, yerr], strict=True): if flag: err = self.errors[kw] # user provided label-matched dataframe of errors @@ -1457,7 +1457,7 @@ def _get_color_mapping(self, c_values: Series) -> dict[str, np.ndarray]: cmap = mpl.colormaps.get_cmap(self.colormap) colors = cmap(np.linspace(0, 1, n_colors)) # RGB tuples - return dict(zip(unique, colors)) + return dict(zip(unique, colors, strict=True)) def _get_norm_and_cmap(self, c_values, color_by_categorical: bool): c = self.c @@ -2178,7 +2178,10 @@ def blank_labeler(label, value): # Blank out labels for values of 0 so they don't overlap # with nonzero wedges if labels is not None: - blabels = [blank_labeler(left, value) for left, value in zip(labels, y)] + blabels = [ + blank_labeler(left, value) + for left, value in zip(labels, y, strict=True) + ] else: blabels = None results = ax.pie(y, labels=blabels, **kwds) @@ -2197,7 +2200,7 @@ def blank_labeler(label, value): # leglabels is used for legend labels leglabels = labels if labels is not None else idx - for _patch, _leglabel in zip(patches, leglabels): + for _patch, _leglabel in zip(patches, leglabels, strict=True): self._append_legend_handles_labels(_patch, _leglabel) def _post_plot_logic(self, ax: Axes, data) -> None: diff --git a/pandas/plotting/_matplotlib/hist.py b/pandas/plotting/_matplotlib/hist.py index ae2e666bf5f1a..029db85b315fd 100644 --- a/pandas/plotting/_matplotlib/hist.py +++ b/pandas/plotting/_matplotlib/hist.py @@ -323,7 +323,7 @@ def _grouped_plot( naxes=naxes, figsize=figsize, sharex=sharex, sharey=sharey, ax=ax, layout=layout ) - for ax, (key, group) in zip(flatten_axes(axes), grouped): + for ax, (key, group) in zip(flatten_axes(axes), grouped, strict=False): if numeric_only and isinstance(group, ABCDataFrame): group = group._get_numeric_data() plotf(group, ax, **kwargs) @@ -557,7 +557,7 @@ def hist_frame( ) can_set_label = "label" not in kwds - for ax, col in zip(flatten_axes(axes), data.columns): + for ax, col in zip(flatten_axes(axes), data.columns, strict=False): if legend and can_set_label: kwds["label"] = col ax.hist(data[col].dropna().values, bins=bins, **kwds) diff --git a/pandas/plotting/_matplotlib/misc.py b/pandas/plotting/_matplotlib/misc.py index 4a891ec27e8cb..271b8f1dc7dc9 100644 --- a/pandas/plotting/_matplotlib/misc.py +++ b/pandas/plotting/_matplotlib/misc.py @@ -191,7 +191,7 @@ def normalize(series): ax.add_patch(mpl.patches.Circle((0.0, 0.0), radius=1.0, facecolor="none")) - for xy, name in zip(s, df.columns): + for xy, name in zip(s, df.columns, strict=True): ax.add_patch(mpl.patches.Circle(xy, radius=0.025, facecolor="gray")) if xy[0] < 0.0 and xy[1] < 0.0: @@ -266,7 +266,7 @@ def f(t): color_values = get_standard_colors( num_colors=len(classes), colormap=colormap, color_type="random", color=color ) - colors = dict(zip(classes, color_values)) + colors = dict(zip(classes, color_values, strict=False)) if ax is None: ax = plt.gca() ax.set_xlim(-np.pi, np.pi) @@ -399,7 +399,7 @@ def parallel_coordinates( if sort_labels: classes = sorted(classes) color_values = sorted(color_values) - colors = dict(zip(classes, color_values)) + colors = dict(zip(classes, color_values, strict=True)) for i in range(n): y = df.iloc[i].values diff --git a/pyproject.toml b/pyproject.toml index 7c7cf0c2fc619..f5a34d71c815f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -494,11 +494,6 @@ exclude = [ "pandas/io/sql.py" = ["B905"] "pandas/io/stata.py" = ["B905"] "pandas/io/xml.py" = ["B905"] -"pandas/plotting/_core.py" = ["B905"] -"pandas/plotting/_matplotlib/boxplot.py" = ["B905"] -"pandas/plotting/_matplotlib/core.py" = ["B905"] -"pandas/plotting/_matplotlib/hist.py" = ["B905"] -"pandas/plotting/_matplotlib/misc.py" = ["B905"] "pandas/_testing/asserters.py" = ["B905"] "pandas/_testing/_warnings.py" = ["B905"] "pandas/tests/apply/test_series_apply.py" = ["B905"]