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

Skip to content

Commit b64e2d1

Browse files
author
cclauss
committed
Convert six.moves.xrange() to range() for Python 3
1 parent fbc6983 commit b64e2d1

20 files changed

+59
-75
lines changed

lib/matplotlib/animation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
unicode_literals)
2222

2323
import six
24-
from six.moves import xrange, zip
24+
from six.moves import zip
2525

2626
import abc
2727
import contextlib
@@ -1680,7 +1680,7 @@ def __init__(self, fig, func, frames=None, init_func=None, fargs=None,
16801680
if hasattr(frames, '__len__'):
16811681
self.save_count = len(frames)
16821682
else:
1683-
self._iter_gen = lambda: iter(xrange(frames))
1683+
self._iter_gen = lambda: iter(range(frames))
16841684
self.save_count = frames
16851685

16861686
if self.save_count is None:

lib/matplotlib/axes/_axes.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
unicode_literals)
33

44
import six
5-
from six.moves import xrange, zip, zip_longest
5+
from six.moves import zip, zip_longest
66

77
import functools
88
import itertools
@@ -3923,7 +3923,7 @@ def dopatch(xs, ys, **kwargs):
39233923
else:
39243924
def doplot(*args, **kwargs):
39253925
shuffled = []
3926-
for i in xrange(0, len(args), 2):
3926+
for i in range(0, len(args), 2):
39273927
shuffled.extend([args[i + 1], args[i]])
39283928
return self.plot(*shuffled, **kwargs)
39293929

@@ -3937,7 +3937,7 @@ def dopatch(xs, ys, **kwargs):
39373937
"values must have same the length")
39383938
# check position
39393939
if positions is None:
3940-
positions = list(xrange(1, N + 1))
3940+
positions = list(range(1, N + 1))
39413941
elif len(positions) != N:
39423942
raise ValueError(datashape_message.format("positions"))
39433943

@@ -4558,31 +4558,31 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
45584558

45594559
# create accumulation arrays
45604560
lattice1 = np.empty((nx1, ny1), dtype=object)
4561-
for i in xrange(nx1):
4562-
for j in xrange(ny1):
4561+
for i in range(nx1):
4562+
for j in range(ny1):
45634563
lattice1[i, j] = []
45644564
lattice2 = np.empty((nx2, ny2), dtype=object)
4565-
for i in xrange(nx2):
4566-
for j in xrange(ny2):
4565+
for i in range(nx2):
4566+
for j in range(ny2):
45674567
lattice2[i, j] = []
45684568

4569-
for i in xrange(len(x)):
4569+
for i in range(len(x)):
45704570
if bdist[i]:
45714571
if 0 <= ix1[i] < nx1 and 0 <= iy1[i] < ny1:
45724572
lattice1[ix1[i], iy1[i]].append(C[i])
45734573
else:
45744574
if 0 <= ix2[i] < nx2 and 0 <= iy2[i] < ny2:
45754575
lattice2[ix2[i], iy2[i]].append(C[i])
45764576

4577-
for i in xrange(nx1):
4578-
for j in xrange(ny1):
4577+
for i in range(nx1):
4578+
for j in range(ny1):
45794579
vals = lattice1[i, j]
45804580
if len(vals) > mincnt:
45814581
lattice1[i, j] = reduce_C_function(vals)
45824582
else:
45834583
lattice1[i, j] = np.nan
4584-
for i in xrange(nx2):
4585-
for j in xrange(ny2):
4584+
for i in range(nx2):
4585+
for j in range(ny2):
45864586
vals = lattice2[i, j]
45874587
if len(vals) > mincnt:
45884588
lattice2[i, j] = reduce_C_function(vals)
@@ -6410,7 +6410,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
64106410
"""
64116411
# Avoid shadowing the builtin.
64126412
bin_range = range
6413-
del range
6413+
from builtins import range
64146414

64156415
if not self._hold:
64166416
self.cla()
@@ -6480,7 +6480,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
64806480
'weights should have the same shape as x')
64816481

64826482
if color is None:
6483-
color = [self._get_lines.get_next_color() for i in xrange(nx)]
6483+
color = [self._get_lines.get_next_color() for i in range(nx)]
64846484
else:
64856485
color = mcolors.to_rgba_array(color)
64866486
if len(color) != nx:
@@ -6507,7 +6507,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
65076507
tops = []
65086508
mlast = None
65096509
# Loop through datasets
6510-
for i in xrange(nx):
6510+
for i in range(nx):
65116511
# this will automatically overwrite bins,
65126512
# so that each histogram uses the same bins
65136513
m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from collections import OrderedDict
55

66
import six
7-
from six.moves import xrange
87

98
import itertools
109
import warnings
@@ -393,7 +392,7 @@ def _plot_args(self, tup, kwargs):
393392
if ncx > 1 and ncy > 1 and ncx != ncy:
394393
cbook.warn_deprecated("2.2", "cycling among columns of inputs "
395394
"with non-matching shapes is deprecated.")
396-
for j in xrange(max(ncx, ncy)):
395+
for j in range(max(ncx, ncy)):
397396
seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
398397
ret.append(seg)
399398
return ret

lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
unicode_literals)
3737

3838
import six
39-
from six.moves import xrange
4039

4140
from contextlib import contextmanager
4241
from functools import partial
@@ -440,7 +439,7 @@ def _iter_collection_raw_paths(self, master_transform, paths,
440439
return
441440

442441
transform = transforms.IdentityTransform()
443-
for i in xrange(N):
442+
for i in range(N):
444443
path = paths[i % Npaths]
445444
if Ntransforms:
446445
transform = Affine2D(all_transforms[i % Ntransforms])
@@ -518,7 +517,7 @@ def _iter_collection(self, gc, master_transform, all_transforms,
518517
gc0.set_linewidth(0.0)
519518

520519
xo, yo = 0, 0
521-
for i in xrange(N):
520+
for i in range(N):
522521
path_id = path_ids[i % Npaths]
523522
if Noffsets:
524523
xo, yo = toffsets[i % Noffsets]

lib/matplotlib/backends/backend_svg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import six
77
from six import unichr
8-
from six.moves import xrange
98

109
import base64
1110
import codecs
@@ -1112,7 +1111,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
11121111
same_y = True
11131112
if len(chars) > 1:
11141113
last_y = chars[0][1]
1115-
for i in xrange(1, len(chars)):
1114+
for i in range(1, len(chars)):
11161115
if chars[i][1] != last_y:
11171116
same_y = False
11181117
break

lib/matplotlib/backends/backend_wx.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
unicode_literals)
1818

1919
import six
20-
from six.moves import xrange
21-
import six
2220

2321
import sys
2422
import os
@@ -1448,7 +1446,7 @@ def updateAxes(self, maxAxis):
14481446
for menuId in self._axisId[maxAxis:]:
14491447
self._menu.Delete(menuId)
14501448
self._axisId = self._axisId[:maxAxis]
1451-
self._toolbar.set_active(list(xrange(maxAxis)))
1449+
self._toolbar.set_active(list(range(maxAxis)))
14521450

14531451
def getActiveAxes(self):
14541452
"""Return a list of the selected axes."""

lib/matplotlib/colorbar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ def _edges(self, X, Y):
498498
# Using the non-array form of these line segments is much
499499
# simpler than making them into arrays.
500500
if self.orientation == 'vertical':
501-
return [list(zip(X[i], Y[i])) for i in xrange(1, N - 1)]
501+
return [list(zip(X[i], Y[i])) for i in range(1, N - 1)]
502502
else:
503-
return [list(zip(Y[i], X[i])) for i in xrange(1, N - 1)]
503+
return [list(zip(Y[i], X[i])) for i in range(1, N - 1)]
504504

505505
def _add_solids(self, X, Y, C):
506506
'''
@@ -1337,7 +1337,7 @@ def _add_solids(self, X, Y, C):
13371337
hatches = self.mappable.hatches * n_segments
13381338

13391339
patches = []
1340-
for i in xrange(len(X) - 1):
1340+
for i in range(len(X) - 1):
13411341
val = C[i][0]
13421342
hatch = hatches[i]
13431343

lib/matplotlib/contour.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
unicode_literals)
66

77
import six
8-
from six.moves import xrange
98

109
import warnings
1110
import matplotlib as mpl
@@ -164,7 +163,7 @@ def clabel(self, *args, **kwargs):
164163
self.rightside_up = kwargs.get('rightside_up', True)
165164
if len(args) == 0:
166165
levels = self.levels
167-
indices = list(xrange(len(self.cvalues)))
166+
indices = list(range(len(self.cvalues)))
168167
elif len(args) == 1:
169168
levlabs = list(args[0])
170169
indices, levels = [], []
@@ -190,7 +189,7 @@ def clabel(self, *args, **kwargs):
190189
self.labelCValueList = np.take(self.cvalues, self.labelIndiceList)
191190
else:
192191
cmap = colors.ListedColormap(_colors, N=len(self.labelLevelList))
193-
self.labelCValueList = list(xrange(len(self.labelLevelList)))
192+
self.labelCValueList = list(range(len(self.labelLevelList)))
194193
self.labelMappable = cm.ScalarMappable(cmap=cmap,
195194
norm=colors.NoNorm())
196195

@@ -1340,7 +1339,7 @@ def find_nearest_contour(self, x, y, indices=None, pixel=True):
13401339
# Nonetheless, improvements could probably be made.
13411340

13421341
if indices is None:
1343-
indices = list(xrange(len(self.levels)))
1342+
indices = list(range(len(self.levels)))
13441343

13451344
dmin = np.inf
13461345
conmin = None

lib/matplotlib/hatch.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
unicode_literals)
77

88
import six
9-
from six.moves import xrange
109

1110
import numpy as np
1211
from matplotlib.path import Path
@@ -115,7 +114,7 @@ def set_vertices_and_codes(self, vertices, codes):
115114
shape_size = len(shape_vertices)
116115

117116
cursor = 0
118-
for row in xrange(self.num_rows + 1):
117+
for row in range(self.num_rows + 1):
119118
if row % 2 == 0:
120119
cols = np.linspace(0.0, 1.0, self.num_rows + 1, True)
121120
else:

lib/matplotlib/markers.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
unicode_literals)
8888

8989
import six
90-
from six.moves import xrange
9190

9291
from collections import Sized
9392
from numbers import Number
@@ -101,7 +100,7 @@
101100
# special-purpose marker identifiers:
102101
(TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN,
103102
CARETLEFT, CARETRIGHT, CARETUP, CARETDOWN,
104-
CARETLEFTBASE, CARETRIGHTBASE, CARETUPBASE, CARETDOWNBASE) = xrange(12)
103+
CARETLEFTBASE, CARETRIGHTBASE, CARETUPBASE, CARETDOWNBASE) = range(12)
105104

106105
_empty_path = Path(np.empty((0, 2)))
107106

lib/matplotlib/mlab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
unicode_literals)
167167

168168
import six
169-
from six.moves import map, xrange, zip
169+
from six.moves import map, zip
170170

171171
import copy
172172
import csv
@@ -1453,7 +1453,7 @@ def cohere_pairs(X, ij, NFFT=256, Fs=2, detrend=detrend_none,
14531453
windowVals = window
14541454
else:
14551455
windowVals = window(np.ones(NFFT, X.dtype))
1456-
ind = list(xrange(0, numRows-NFFT+1, NFFT-noverlap))
1456+
ind = list(range(0, numRows-NFFT+1, NFFT-noverlap))
14571457
numSlices = len(ind)
14581458
FFTSlices = {}
14591459
FFTConjSlices = {}

lib/matplotlib/offsetbox.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
unicode_literals)
1919

2020
import six
21-
from six.moves import xrange, zip
21+
from six.moves import zip
2222

2323
import warnings
2424
import matplotlib.transforms as mtransforms
@@ -1194,7 +1194,7 @@ def _get_anchored_bbox(self, loc, bbox, parentbbox, borderpad):
11941194
"""
11951195
assert loc in range(1, 11) # called only internally
11961196

1197-
BEST, UR, UL, LL, LR, R, CL, CR, LC, UC, C = xrange(11)
1197+
BEST, UR, UL, LL, LR, R, CL, CR, LC, UC, C = range(11)
11981198

11991199
anchor_coefs = {UR: "NE",
12001200
UL: "NW",

lib/matplotlib/stackplot.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
from __future__ import (absolute_import, division, print_function,
1010
unicode_literals)
1111

12-
import six
13-
from six.moves import xrange
14-
1512
from cycler import cycler
1613
import numpy as np
1714

@@ -120,7 +117,7 @@ def stackplot(axes, x, *args, **kwargs):
120117
r = [coll]
121118

122119
# Color between array i-1 and array i
123-
for i in xrange(len(y) - 1):
120+
for i in range(len(y) - 1):
124121
color = axes._get_lines.get_next_color()
125122
r.append(axes.fill_between(x, stack[i, :], stack[i + 1, :],
126123
facecolor=color, label=next(labels, None),

lib/matplotlib/streamplot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
unicode_literals)
77

88
import six
9-
from six.moves import xrange
109

1110
import numpy as np
1211
import matplotlib
@@ -648,7 +647,7 @@ def _gen_starting_points(shape):
648647
x, y = 0, 0
649648
i = 0
650649
direction = 'right'
651-
for i in xrange(nx * ny):
650+
for i in range(nx * ny):
652651

653652
yield x, y
654653

lib/matplotlib/table.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
unicode_literals)
2424

2525
import six
26-
from six.moves import xrange
2726

2827
import warnings
2928

@@ -551,7 +550,7 @@ def _update_positions(self, renderer):
551550
else:
552551
# Position using loc
553552
(BEST, UR, UL, LL, LR, CL, CR, LC, UC, C,
554-
TR, TL, BL, BR, R, L, T, B) = xrange(len(self.codes))
553+
TR, TL, BL, BR, R, L, T, B) = range(len(self.codes))
555554
# defaults for center
556555
ox = (0.5 - w / 2) - l
557556
oy = (0.5 - h / 2) - b
@@ -670,24 +669,24 @@ def table(ax,
670669
height = table._approx_text_height()
671670

672671
# Add the cells
673-
for row in xrange(rows):
674-
for col in xrange(cols):
672+
for row in range(rows):
673+
for col in range(cols):
675674
table.add_cell(row + offset, col,
676675
width=colWidths[col], height=height,
677676
text=cellText[row][col],
678677
facecolor=cellColours[row][col],
679678
loc=cellLoc)
680679
# Do column labels
681680
if colLabels is not None:
682-
for col in xrange(cols):
681+
for col in range(cols):
683682
table.add_cell(0, col,
684683
width=colWidths[col], height=height,
685684
text=colLabels[col], facecolor=colColours[col],
686685
loc=colLoc)
687686

688687
# Do row labels
689688
if rowLabels is not None:
690-
for row in xrange(rows):
689+
for row in range(rows):
691690
table.add_cell(row + offset, -1,
692691
width=rowLabelWidth or 1e-15, height=height,
693692
text=rowLabels[row], facecolor=rowColours[row],

0 commit comments

Comments
 (0)