Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3309368

Browse files
committed
Use itertools.pairwise instead of zip
This was added in 3.10.
1 parent 6946a76 commit 3309368

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

galleries/examples/units/basic_units.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
88
"""
99

10+
import itertools
1011
import math
1112

1213
from packaging.version import parse as parse_version
@@ -254,7 +255,7 @@ def get_unit(self):
254255

255256
class UnitResolver:
256257
def addition_rule(self, units):
257-
for unit_1, unit_2 in zip(units[:-1], units[1:]):
258+
for unit_1, unit_2 in itertools.pairwise(units):
258259
if unit_1 != unit_2:
259260
return NotImplemented
260261
return units[0]

lib/matplotlib/tests/test_cbook.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,8 @@ def check(x, rstride, cstride):
799799
row_inds = [*range(0, rows-1, rstride), rows-1]
800800
col_inds = [*range(0, cols-1, cstride), cols-1]
801801
polys = []
802-
for rs, rs_next in zip(row_inds[:-1], row_inds[1:]):
803-
for cs, cs_next in zip(col_inds[:-1], col_inds[1:]):
802+
for rs, rs_next in itertools.pairwise(row_inds):
803+
for cs, cs_next in itertools.pairwise(col_inds):
804804
# +1 ensures we share edges between polygons
805805
ps = cbook._array_perimeter(x[rs:rs_next+1, cs:cs_next+1]).T
806806
polys.append(ps)

lib/matplotlib/transforms.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838

3939
import copy
4040
import functools
41+
import itertools
4142
import textwrap
4243
import weakref
4344
import math
@@ -553,7 +554,7 @@ def splitx(self, *args):
553554
x0, y0, x1, y1 = self.extents
554555
w = x1 - x0
555556
return [Bbox([[x0 + xf0 * w, y0], [x0 + xf1 * w, y1]])
556-
for xf0, xf1 in zip(xf[:-1], xf[1:])]
557+
for xf0, xf1 in itertools.pairwise(xf)]
557558

558559
def splity(self, *args):
559560
"""
@@ -564,7 +565,7 @@ def splity(self, *args):
564565
x0, y0, x1, y1 = self.extents
565566
h = y1 - y0
566567
return [Bbox([[x0, y0 + yf0 * h], [x1, y0 + yf1 * h]])
567-
for yf0, yf1 in zip(yf[:-1], yf[1:])]
568+
for yf0, yf1 in itertools.pairwise(yf)]
568569

569570
def count_contains(self, vertices):
570571
"""

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2206,8 +2206,8 @@ def plot_surface(self, X, Y, Z, *, norm=None, vmin=None,
22062206
col_inds = list(range(0, cols-1, cstride)) + [cols-1]
22072207

22082208
polys = []
2209-
for rs, rs_next in zip(row_inds[:-1], row_inds[1:]):
2210-
for cs, cs_next in zip(col_inds[:-1], col_inds[1:]):
2209+
for rs, rs_next in itertools.pairwise(row_inds):
2210+
for cs, cs_next in itertools.pairwise(col_inds):
22112211
ps = [
22122212
# +1 ensures we share edges between polygons
22132213
cbook._array_perimeter(a[rs:rs_next+1, cs:cs_next+1])
@@ -3385,7 +3385,7 @@ def permutation_matrices(n):
33853385
voxel_faces[i0].append(p0 + square_rot_neg)
33863386

33873387
# draw middle faces
3388-
for r1, r2 in zip(rinds[:-1], rinds[1:]):
3388+
for r1, r2 in itertools.pairwise(rinds):
33893389
p1 = permute.dot([p, q, r1])
33903390
p2 = permute.dot([p, q, r2])
33913391

0 commit comments

Comments
 (0)