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

Skip to content

Commit dec88cf

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

File tree

6 files changed

+28
-27
lines changed

6 files changed

+28
-27
lines changed

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/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 zip
12+
from six.moves import xrange, 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, range(len(seq))):
944+
for (word, ind) in zip(seq, xrange(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 range(1, len(seq)):
1101+
for i in xrange(1, len(seq)):
11021102
thisval = seq[i]
11031103
if thisval != val:
11041104
return False

lib/matplotlib/colorbar.py

Lines changed: 3 additions & 3 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 zip
25+
from six.moves import xrange, zip
2626

2727
import warnings
2828

@@ -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 range(N)]
564+
xy = [list(zip(X[i], Y[i])) for i in xrange(N)]
565565
else:
566-
xy = [list(zip(Y[i], X[i])) for i in range(N)]
566+
xy = [list(zip(Y[i], X[i])) for i in xrange(N)]
567567
col = collections.LineCollection(xy, linewidths=linewidths)
568568

569569
if erase and self.lines:

lib/matplotlib/mathtext.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 import unichr
21+
from six import unichr, xrange
2222

2323
import os
2424
from math import ceil
@@ -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 range(1, loc + 1):
2644+
for i in xrange(1, loc + 1):
26452645
prev_char = s[loc-i]
26462646
if prev_char != ' ':
26472647
break

lib/matplotlib/sphinxext/plot_directive.py

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

140140
import six
141+
from six.moves import xrange
141142

142143
import sys, os, shutil, io, re, textwrap
143144
from os.path import relpath
@@ -596,7 +597,7 @@ def render_figures(code, code_path, output_dir, output_base, context,
596597
all_exists = True
597598
for i, code_piece in enumerate(code_pieces):
598599
images = []
599-
for j in range(1000):
600+
for j in xrange(1000):
600601
if len(code_pieces) > 1:
601602
img = ImageFile('%s_%02d_%02d' % (output_base, i, j),
602603
output_dir)

lib/mpl_toolkits/axes_grid1/colorbar.py

Lines changed: 3 additions & 3 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 zip
25+
from six.moves import xrange, zip
2626

2727
import numpy as np
2828
import matplotlib as mpl
@@ -529,9 +529,9 @@ def _edges(self, X, Y):
529529
# Using the non-array form of these line segments is much
530530
# simpler than making them into arrays.
531531
if self.orientation == 'vertical':
532-
return [list(zip(X[i], Y[i])) for i in range(1, N-1)]
532+
return [list(zip(X[i], Y[i])) for i in xrange(1, N-1)]
533533
else:
534-
return [list(zip(Y[i], X[i])) for i in range(1, N-1)]
534+
return [list(zip(Y[i], X[i])) for i in xrange(1, N-1)]
535535

536536
def _add_solids(self, X, Y, C):
537537
'''

0 commit comments

Comments
 (0)