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

Skip to content

Commit f73b62c

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

22 files changed

+57
-74
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
@@ -1682,7 +1682,7 @@ def __init__(self, fig, func, frames=None, init_func=None, fargs=None,
16821682
if hasattr(frames, '__len__'):
16831683
self.save_count = len(frames)
16841684
else:
1685-
self._iter_gen = lambda: iter(xrange(frames))
1685+
self._iter_gen = lambda: iter(range(frames))
16861686
self.save_count = frames
16871687

16881688
if self.save_count is None:

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
@@ -1449,7 +1447,7 @@ def updateAxes(self, maxAxis):
14491447
for menuId in self._axisId[maxAxis:]:
14501448
self._menu.Delete(menuId)
14511449
self._axisId = self._axisId[:maxAxis]
1452-
self._toolbar.set_active(list(xrange(maxAxis)))
1450+
self._toolbar.set_active(list(range(maxAxis)))
14531451

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

lib/matplotlib/cbook/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from __future__ import absolute_import, division, print_function
1010

1111
import six
12-
from six.moves import xrange, zip
12+
from six.moves import zip
1313
import bz2
1414
import collections
1515
import contextlib
@@ -941,7 +941,7 @@ def get_split_ind(seq, N):
941941

942942
s_len = 0
943943
# todo: use Alex's xrange pattern from the cbook for efficiency
944-
for (word, ind) in zip(seq, xrange(len(seq))):
944+
for (word, ind) in zip(seq, range(len(seq))):
945945
s_len += len(word) + 1 # +1 to account for the len(' ')
946946
if s_len >= N:
947947
return ind
@@ -1098,7 +1098,7 @@ def allequal(seq):
10981098
if len(seq) < 2:
10991099
return True
11001100
val = seq[0]
1101-
for i in xrange(1, len(seq)):
1101+
for i in range(1, len(seq)):
11021102
thisval = seq[i]
11031103
if thisval != val:
11041104
return False

lib/matplotlib/colorbar.py

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

2424
import six
25-
from six.moves import xrange, zip
25+
from six.moves import zip
2626

2727
import warnings
2828

@@ -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
'''
@@ -561,9 +561,9 @@ def add_lines(self, levels, colors, linewidths, erase=True):
561561
x = np.array([0.0, 1.0])
562562
X, Y = np.meshgrid(x, y)
563563
if self.orientation == 'vertical':
564-
xy = [list(zip(X[i], Y[i])) for i in xrange(N)]
564+
xy = [list(zip(X[i], Y[i])) for i in range(N)]
565565
else:
566-
xy = [list(zip(Y[i], X[i])) for i in xrange(N)]
566+
xy = [list(zip(Y[i], X[i])) for i in range(N)]
567567
col = collections.LineCollection(xy, linewidths=linewidths)
568568

569569
if erase and self.lines:
@@ -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/mathtext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,7 +2641,7 @@ def symbol(self, s, loc, toks):
26412641
if c in self._spaced_symbols:
26422642
# iterate until we find previous character, needed for cases
26432643
# such as ${ -2}$, $ -2$, or $ -2$.
2644-
for i in six.moves.xrange(1, loc + 1):
2644+
for i in range(1, loc + 1):
26452645
prev_char = s[loc-i]
26462646
if prev_char != ' ':
26472647
break
@@ -2660,11 +2660,11 @@ def symbol(self, s, loc, toks):
26602660
# Do not space commas between brackets
26612661
if c == ',':
26622662
prev_char, next_char = '', ''
2663-
for i in six.moves.xrange(1, loc + 1):
2663+
for i in range(1, loc + 1):
26642664
prev_char = s[loc - i]
26652665
if prev_char != ' ':
26662666
break
2667-
for i in six.moves.xrange(1, len(s) - loc):
2667+
for i in range(1, len(s) - loc):
26682668
next_char = s[loc + i]
26692669
if next_char != ' ':
26702670
break

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
@@ -1197,7 +1197,7 @@ def _get_anchored_bbox(self, loc, bbox, parentbbox, borderpad):
11971197
"""
11981198
assert loc in range(1, 11) # called only internally
11991199

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

12021202
anchor_coefs = {UR: "NE",
12031203
UL: "NW",

lib/matplotlib/sphinxext/plot_directive.py

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

140140
import six
141-
from six.moves import xrange
142141

143142
import sys, os, shutil, io, re, textwrap
144143
from os.path import relpath
@@ -597,7 +596,7 @@ def render_figures(code, code_path, output_dir, output_base, context,
597596
all_exists = True
598597
for i, code_piece in enumerate(code_pieces):
599598
images = []
600-
for j in xrange(1000):
599+
for j in range(1000):
601600
if len(code_pieces) > 1:
602601
img = ImageFile('%s_%02d_%02d' % (output_base, i, j),
603602
output_dir)

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)