Skip to content

Commit d18f9a2

Browse files
authored
Zip Strict for pandas/plotting #62469 (#62478)
1 parent 035d5b4 commit d18f9a2

File tree

6 files changed

+25
-22
lines changed

6 files changed

+25
-22
lines changed

pandas/plotting/_core.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,10 @@ def _get_call_args(backend_name: str, data: Series | DataFrame, args, kwargs):
962962
if args and isinstance(data, ABCSeries):
963963
positional_args = str(args)[1:-1]
964964
keyword_args = ", ".join(
965-
[f"{name}={value!r}" for (name, _), value in zip(arg_def, args)]
965+
[
966+
f"{name}={value!r}"
967+
for (name, _), value in zip(arg_def, args, strict=False)
968+
]
966969
)
967970
msg = (
968971
"`Series.plot()` should not be called with positional "
@@ -973,7 +976,9 @@ def _get_call_args(backend_name: str, data: Series | DataFrame, args, kwargs):
973976
)
974977
raise TypeError(msg)
975978

976-
pos_args = {name: value for (name, _), value in zip(arg_def, args)}
979+
pos_args = {
980+
name: value for (name, _), value in zip(arg_def, args, strict=False)
981+
}
977982
if backend_name == "pandas.plotting._matplotlib":
978983
kwargs = dict(arg_def, **pos_args, **kwargs)
979984
else:

pandas/plotting/_matplotlib/boxplot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ def _grouped_plot_by_column(
321321

322322
ax_values = []
323323

324-
for ax, col in zip(flatten_axes(axes), columns):
324+
for ax, col in zip(flatten_axes(axes), columns, strict=False):
325325
gp_col = grouped[col]
326-
keys, values = zip(*gp_col)
326+
keys, values = zip(*gp_col, strict=True)
327327
re_plotf = plotf(keys, values, ax, xlabel=xlabel, ylabel=ylabel, **kwargs)
328328
ax.set_title(col)
329329
ax_values.append(re_plotf)
@@ -380,7 +380,7 @@ def _get_colors():
380380
# taken from the colors dict parameter
381381
# "boxes" value placed in position 0, "whiskers" in 1, etc.
382382
valid_keys = ["boxes", "whiskers", "medians", "caps"]
383-
key_to_index = dict(zip(valid_keys, range(4)))
383+
key_to_index = dict(zip(valid_keys, range(4), strict=True))
384384
for key, value in colors.items():
385385
if key in valid_keys:
386386
result[key_to_index[key]] = value
@@ -530,7 +530,7 @@ def boxplot_frame_groupby(
530530
layout=layout,
531531
)
532532
data = {}
533-
for (key, group), ax in zip(grouped, flatten_axes(axes)):
533+
for (key, group), ax in zip(grouped, flatten_axes(axes), strict=False):
534534
d = group.boxplot(
535535
ax=ax, column=column, fontsize=fontsize, rot=rot, grid=grid, **kwds
536536
)
@@ -539,7 +539,7 @@ def boxplot_frame_groupby(
539539
ret = pd.Series(data)
540540
maybe_adjust_figure(fig, bottom=0.15, top=0.9, left=0.1, right=0.9, wspace=0.2)
541541
else:
542-
keys, frames = zip(*grouped)
542+
keys, frames = zip(*grouped, strict=True)
543543
df = pd.concat(frames, keys=keys, axis=1)
544544

545545
# GH 16748, DataFrameGroupby fails when subplots=False and `column` argument

pandas/plotting/_matplotlib/core.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ def _adorn_subplots(self, fig: Figure) -> None:
817817
f"number of columns = {self.nseries}"
818818
)
819819

820-
for ax, title in zip(self.axes, self.title):
820+
for ax, title in zip(self.axes, self.title, strict=False):
821821
ax.set_title(title)
822822
else:
823823
fig.suptitle(self.title)
@@ -1216,7 +1216,7 @@ def _get_errorbars(
12161216
) -> dict[str, Any]:
12171217
errors = {}
12181218

1219-
for kw, flag in zip(["xerr", "yerr"], [xerr, yerr]):
1219+
for kw, flag in zip(["xerr", "yerr"], [xerr, yerr], strict=True):
12201220
if flag:
12211221
err = self.errors[kw]
12221222
# user provided label-matched dataframe of errors
@@ -1457,7 +1457,7 @@ def _get_color_mapping(self, c_values: Series) -> dict[str, np.ndarray]:
14571457
cmap = mpl.colormaps.get_cmap(self.colormap)
14581458
colors = cmap(np.linspace(0, 1, n_colors)) # RGB tuples
14591459

1460-
return dict(zip(unique, colors))
1460+
return dict(zip(unique, colors, strict=True))
14611461

14621462
def _get_norm_and_cmap(self, c_values, color_by_categorical: bool):
14631463
c = self.c
@@ -2178,7 +2178,10 @@ def blank_labeler(label, value):
21782178
# Blank out labels for values of 0 so they don't overlap
21792179
# with nonzero wedges
21802180
if labels is not None:
2181-
blabels = [blank_labeler(left, value) for left, value in zip(labels, y)]
2181+
blabels = [
2182+
blank_labeler(left, value)
2183+
for left, value in zip(labels, y, strict=True)
2184+
]
21822185
else:
21832186
blabels = None
21842187
results = ax.pie(y, labels=blabels, **kwds)
@@ -2197,7 +2200,7 @@ def blank_labeler(label, value):
21972200

21982201
# leglabels is used for legend labels
21992202
leglabels = labels if labels is not None else idx
2200-
for _patch, _leglabel in zip(patches, leglabels):
2203+
for _patch, _leglabel in zip(patches, leglabels, strict=True):
22012204
self._append_legend_handles_labels(_patch, _leglabel)
22022205

22032206
def _post_plot_logic(self, ax: Axes, data) -> None:

pandas/plotting/_matplotlib/hist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def _grouped_plot(
323323
naxes=naxes, figsize=figsize, sharex=sharex, sharey=sharey, ax=ax, layout=layout
324324
)
325325

326-
for ax, (key, group) in zip(flatten_axes(axes), grouped):
326+
for ax, (key, group) in zip(flatten_axes(axes), grouped, strict=False):
327327
if numeric_only and isinstance(group, ABCDataFrame):
328328
group = group._get_numeric_data()
329329
plotf(group, ax, **kwargs)
@@ -557,7 +557,7 @@ def hist_frame(
557557
)
558558
can_set_label = "label" not in kwds
559559

560-
for ax, col in zip(flatten_axes(axes), data.columns):
560+
for ax, col in zip(flatten_axes(axes), data.columns, strict=False):
561561
if legend and can_set_label:
562562
kwds["label"] = col
563563
ax.hist(data[col].dropna().values, bins=bins, **kwds)

pandas/plotting/_matplotlib/misc.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def normalize(series):
191191

192192
ax.add_patch(mpl.patches.Circle((0.0, 0.0), radius=1.0, facecolor="none"))
193193

194-
for xy, name in zip(s, df.columns):
194+
for xy, name in zip(s, df.columns, strict=True):
195195
ax.add_patch(mpl.patches.Circle(xy, radius=0.025, facecolor="gray"))
196196

197197
if xy[0] < 0.0 and xy[1] < 0.0:
@@ -266,7 +266,7 @@ def f(t):
266266
color_values = get_standard_colors(
267267
num_colors=len(classes), colormap=colormap, color_type="random", color=color
268268
)
269-
colors = dict(zip(classes, color_values))
269+
colors = dict(zip(classes, color_values, strict=False))
270270
if ax is None:
271271
ax = plt.gca()
272272
ax.set_xlim(-np.pi, np.pi)
@@ -399,7 +399,7 @@ def parallel_coordinates(
399399
if sort_labels:
400400
classes = sorted(classes)
401401
color_values = sorted(color_values)
402-
colors = dict(zip(classes, color_values))
402+
colors = dict(zip(classes, color_values, strict=True))
403403

404404
for i in range(n):
405405
y = df.iloc[i].values

pyproject.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,6 @@ exclude = [
494494
"pandas/io/sql.py" = ["B905"]
495495
"pandas/io/stata.py" = ["B905"]
496496
"pandas/io/xml.py" = ["B905"]
497-
"pandas/plotting/_core.py" = ["B905"]
498-
"pandas/plotting/_matplotlib/boxplot.py" = ["B905"]
499-
"pandas/plotting/_matplotlib/core.py" = ["B905"]
500-
"pandas/plotting/_matplotlib/hist.py" = ["B905"]
501-
"pandas/plotting/_matplotlib/misc.py" = ["B905"]
502497
"pandas/_testing/asserters.py" = ["B905"]
503498
"pandas/_testing/_warnings.py" = ["B905"]
504499
"pandas/tests/apply/test_series_apply.py" = ["B905"]

0 commit comments

Comments
 (0)