Skip to content

Commit 6fcb267

Browse files
authored
STY: Use strict arg in zip() in pandas/tests/plotting (#63296)
1 parent 25934d6 commit 6fcb267

File tree

8 files changed

+27
-27
lines changed

8 files changed

+27
-27
lines changed

pandas/tests/plotting/common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def _check_data(xp, rs):
8080
rs_lines = rs.get_lines()
8181

8282
assert len(xp_lines) == len(rs_lines)
83-
for xpl, rsl in zip(xp_lines, rs_lines):
83+
for xpl, rsl in zip(xp_lines, rs_lines, strict=True):
8484
xpdata = xpl.get_xydata()
8585
rsdata = rsl.get_xydata()
8686
tm.assert_almost_equal(xpdata, rsdata)
@@ -162,7 +162,7 @@ def _check_colors(collections, linecolors=None, facecolors=None, mapping=None):
162162
linecolors = linecolors[: len(collections)]
163163

164164
assert len(collections) == len(linecolors)
165-
for patch, color in zip(collections, linecolors):
165+
for patch, color in zip(collections, linecolors, strict=True):
166166
if isinstance(patch, Line2D):
167167
result = patch.get_color()
168168
# Line2D may contains string color expression
@@ -181,7 +181,7 @@ def _check_colors(collections, linecolors=None, facecolors=None, mapping=None):
181181
facecolors = facecolors[: len(collections)]
182182

183183
assert len(collections) == len(facecolors)
184-
for patch, color in zip(collections, facecolors):
184+
for patch, color in zip(collections, facecolors, strict=True):
185185
if isinstance(patch, Collection):
186186
# returned as list of np.array
187187
result = patch.get_facecolor()[0]
@@ -211,7 +211,7 @@ def _check_text_labels(texts, expected):
211211
else:
212212
labels = [t.get_text() for t in texts]
213213
assert len(labels) == len(expected)
214-
for label, e in zip(labels, expected):
214+
for label, e in zip(labels, expected, strict=True):
215215
assert label == e
216216

217217

pandas/tests/plotting/frame/test_frame_color.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def test_line_colors(self):
324324
ax2 = df.plot(color=custom_colors)
325325
lines2 = ax2.get_lines()
326326

327-
for l1, l2 in zip(ax.get_lines(), lines2):
327+
for l1, l2 in zip(ax.get_lines(), lines2, strict=True):
328328
assert l1.get_color() == l2.get_color()
329329

330330
@pytest.mark.parametrize("colormap", ["jet", cm.jet])
@@ -380,7 +380,7 @@ def test_line_colors_and_styles_subplots_custom_colors(self, color):
380380
# GH 9894
381381
df = DataFrame(np.random.default_rng(2).standard_normal((5, 5)))
382382
axes = df.plot(color=color, subplots=True)
383-
for ax, c in zip(axes, list(color)):
383+
for ax, c in zip(axes, list(color), strict=True):
384384
_check_colors(ax.get_lines(), linecolors=[c])
385385

386386
def test_line_colors_and_styles_subplots_colormap_hex(self):
@@ -389,7 +389,7 @@ def test_line_colors_and_styles_subplots_colormap_hex(self):
389389
# GH 10299
390390
custom_colors = ["#FF0000", "#0000FF", "#FFFF00", "#000000", "#FFFFFF"]
391391
axes = df.plot(color=custom_colors, subplots=True)
392-
for ax, c in zip(axes, list(custom_colors)):
392+
for ax, c in zip(axes, list(custom_colors), strict=True):
393393
_check_colors(ax.get_lines(), linecolors=[c])
394394

395395
@pytest.mark.parametrize("cmap", ["jet", cm.jet])
@@ -398,7 +398,7 @@ def test_line_colors_and_styles_subplots_colormap_subplot(self, cmap):
398398
df = DataFrame(np.random.default_rng(2).standard_normal((5, 5)))
399399
rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))]
400400
axes = df.plot(colormap=cmap, subplots=True)
401-
for ax, c in zip(axes, rgba_colors):
401+
for ax, c in zip(axes, rgba_colors, strict=True):
402402
_check_colors(ax.get_lines(), linecolors=[c])
403403

404404
def test_line_colors_and_styles_subplots_single_col(self):
@@ -423,7 +423,7 @@ def test_line_colors_and_styles_subplots_list_styles(self):
423423
# list of styles
424424
styles = list("rgcby")
425425
axes = df.plot(style=styles, subplots=True)
426-
for ax, c in zip(axes, styles):
426+
for ax, c in zip(axes, styles, strict=True):
427427
_check_colors(ax.get_lines(), linecolors=[c])
428428

429429
def test_area_colors(self):
@@ -551,7 +551,7 @@ def test_kde_colors_and_styles_subplots_custom_color(self):
551551
df = DataFrame(np.random.default_rng(2).standard_normal((5, 5)))
552552
custom_colors = "rgcby"
553553
axes = df.plot(kind="kde", color=custom_colors, subplots=True)
554-
for ax, c in zip(axes, list(custom_colors)):
554+
for ax, c in zip(axes, list(custom_colors), strict=True):
555555
_check_colors(ax.get_lines(), linecolors=[c])
556556

557557
@pytest.mark.parametrize("colormap", ["jet", cm.jet])
@@ -560,7 +560,7 @@ def test_kde_colors_and_styles_subplots_cmap(self, colormap):
560560
df = DataFrame(np.random.default_rng(2).standard_normal((5, 5)))
561561
rgba_colors = [cm.jet(n) for n in np.linspace(0, 1, len(df))]
562562
axes = df.plot(kind="kde", colormap=colormap, subplots=True)
563-
for ax, c in zip(axes, rgba_colors):
563+
for ax, c in zip(axes, rgba_colors, strict=True):
564564
_check_colors(ax.get_lines(), linecolors=[c])
565565

566566
def test_kde_colors_and_styles_subplots_single_col(self):
@@ -586,7 +586,7 @@ def test_kde_colors_and_styles_subplots_list(self):
586586
# list of styles
587587
styles = list("rgcby")
588588
axes = df.plot(kind="kde", style=styles, subplots=True)
589-
for ax, c in zip(axes, styles):
589+
for ax, c in zip(axes, styles, strict=True):
590590
_check_colors(ax.get_lines(), linecolors=[c])
591591

592592
def test_boxplot_colors(self):
@@ -715,7 +715,7 @@ def test_colors_of_columns_with_same_name(self):
715715
result = df_concat.plot()
716716
legend = result.get_legend()
717717
handles = legend.legend_handles
718-
for legend, line in zip(handles, result.lines):
718+
for legend, line in zip(handles, result.lines, strict=True):
719719
assert legend.get_color() == line.get_color()
720720

721721
def test_invalid_colormap(self):

pandas/tests/plotting/frame/test_frame_groupby.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
class TestDataFramePlotsGroupby:
1212
def _assert_ytickslabels_visibility(self, axes, expected):
13-
for ax, exp in zip(axes, expected):
13+
for ax, exp in zip(axes, expected, strict=True):
1414
_check_visible(ax.get_yticklabels(), visible=exp)
1515

1616
def _assert_xtickslabels_visibility(self, axes, expected):
17-
for ax, exp in zip(axes, expected):
17+
for ax, exp in zip(axes, expected, strict=True):
1818
_check_visible(ax.get_xticklabels(), visible=exp)
1919

2020
@pytest.mark.parametrize(

pandas/tests/plotting/test_boxplot_method.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ def test_boxplot_legacy1_return_type(self, hist_df):
423423

424424
@pytest.mark.slow
425425
def test_boxplot_legacy2(self):
426-
tuples = zip(string.ascii_letters[:10], range(10))
426+
tuples = zip(string.ascii_letters[:10], range(10), strict=True)
427427
df = DataFrame(
428428
np.random.default_rng(2).random((10, 3)),
429429
index=MultiIndex.from_tuples(tuples),
@@ -435,7 +435,7 @@ def test_boxplot_legacy2(self):
435435

436436
@pytest.mark.slow
437437
def test_boxplot_legacy2_return_type(self):
438-
tuples = zip(string.ascii_letters[:10], range(10))
438+
tuples = zip(string.ascii_letters[:10], range(10), strict=True)
439439
df = DataFrame(
440440
np.random.default_rng(2).random((10, 3)),
441441
index=MultiIndex.from_tuples(tuples),
@@ -744,7 +744,7 @@ def test_boxplot_multiindex_column(self):
744744
["bar", "bar", "baz", "baz", "foo", "foo", "qux", "qux"],
745745
["one", "two", "one", "two", "one", "two", "one", "two"],
746746
]
747-
tuples = list(zip(*arrays))
747+
tuples = list(zip(*arrays, strict=True))
748748
index = MultiIndex.from_tuples(tuples, names=["first", "second"])
749749
df = DataFrame(
750750
np.random.default_rng(2).standard_normal((3, 8)),

pandas/tests/plotting/test_datetimelike.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ def test_irregular_datetime64_repr_bug(self):
324324
ret = ser.plot(ax=ax)
325325
assert ret is not None
326326

327-
for rs, xp in zip(ax.get_lines()[0].get_xdata(), ser.index):
327+
for rs, xp in zip(ax.get_lines()[0].get_xdata(), ser.index, strict=True):
328328
assert rs == xp
329329

330330
def test_business_freq(self):
@@ -1150,7 +1150,7 @@ def test_time(self):
11501150
# verify tick labels
11511151
ticks = ax.get_xticks()
11521152
labels = ax.get_xticklabels()
1153-
for _tick, _label in zip(ticks, labels):
1153+
for _tick, _label in zip(ticks, labels, strict=True):
11541154
m, s = divmod(int(_tick), 60)
11551155
h, m = divmod(m, 60)
11561156
rs = _label.get_text()
@@ -1178,7 +1178,7 @@ def test_time_change_xlim(self):
11781178
# verify tick labels
11791179
ticks = ax.get_xticks()
11801180
labels = ax.get_xticklabels()
1181-
for _tick, _label in zip(ticks, labels):
1181+
for _tick, _label in zip(ticks, labels, strict=True):
11821182
m, s = divmod(int(_tick), 60)
11831183
h, m = divmod(m, 60)
11841184
rs = _label.get_text()
@@ -1195,7 +1195,7 @@ def test_time_change_xlim(self):
11951195
# check tick labels again
11961196
ticks = ax.get_xticks()
11971197
labels = ax.get_xticklabels()
1198-
for _tick, _label in zip(ticks, labels):
1198+
for _tick, _label in zip(ticks, labels, strict=True):
11991199
m, s = divmod(int(_tick), 60)
12001200
h, m = divmod(m, 60)
12011201
rs = _label.get_text()
@@ -1223,7 +1223,7 @@ def test_time_musec(self):
12231223
# verify tick labels
12241224
ticks = ax.get_xticks()
12251225
labels = ax.get_xticklabels()
1226-
for _tick, _label in zip(ticks, labels):
1226+
for _tick, _label in zip(ticks, labels, strict=True):
12271227
m, s = divmod(int(_tick), 60)
12281228

12291229
us = round((_tick - int(_tick)) * 1e6)

pandas/tests/plotting/test_groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_groupby_hist_frame_with_legend(self, column, expected_axes_num):
109109

110110
for axes in g.hist(legend=True, column=column):
111111
_check_axes_shape(axes, axes_num=expected_axes_num, layout=expected_layout)
112-
for ax, expected_label in zip(axes[0], expected_labels):
112+
for ax, expected_label in zip(axes[0], expected_labels, strict=True):
113113
_check_legend_labels(ax, expected_label)
114114

115115
@pytest.mark.parametrize("column", [None, "b"])

pandas/tests/plotting/test_hist_method.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def test_hist_with_legend(self, by, column):
532532
_check_axes_shape(axes, axes_num=expected_axes_num, layout=expected_layout)
533533
if by is None and column is None:
534534
axes = axes[0]
535-
for expected_label, ax in zip(expected_labels, axes):
535+
for expected_label, ax in zip(expected_labels, axes, strict=True):
536536
_check_legend_labels(ax, expected_label)
537537

538538
@pytest.mark.parametrize("by", [None, "c"])
@@ -644,7 +644,7 @@ def test_hist_with_nans_and_weights(self):
644644
x for x in ax1.get_children() if isinstance(x, mpl.patches.Rectangle)
645645
]
646646
no_nan_heights = [rect.get_height() for rect in no_nan_rects]
647-
assert all(h0 == h1 for h0, h1 in zip(heights, no_nan_heights))
647+
assert all(h0 == h1 for h0, h1 in zip(heights, no_nan_heights, strict=True))
648648

649649
idxerror_weights = np.array([[0.3, 0.25], [0.45, 0.45]])
650650

pandas/tests/plotting/test_series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ def test_pie_series_autopct_and_fontsize(self):
436436
series.plot.pie, colors=color_args, autopct="%.2f", fontsize=7
437437
)
438438
pcts = [f"{s * 100:.2f}" for s in series.values / series.sum()]
439-
expected_texts = list(chain.from_iterable(zip(series.index, pcts)))
439+
expected_texts = list(chain.from_iterable(zip(series.index, pcts, strict=True)))
440440
_check_text_labels(ax.texts, expected_texts)
441441
for t in ax.texts:
442442
assert t.get_fontsize() == 7

0 commit comments

Comments
 (0)