Skip to content

Commit f73b62c

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

File tree

22 files changed

+57
-74
lines changed

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

0 commit comments

Comments
 (0)