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

Skip to content

Convert six.moves.xrange() to range() for Python 3 #10525

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
unicode_literals)

import six
from six.moves import xrange, zip
from six.moves import zip

import abc
import contextlib
Expand Down Expand Up @@ -1680,7 +1680,7 @@ def __init__(self, fig, func, frames=None, init_func=None, fargs=None,
if hasattr(frames, '__len__'):
self.save_count = len(frames)
else:
self._iter_gen = lambda: iter(xrange(frames))
self._iter_gen = lambda: iter(range(frames))
self.save_count = frames

if self.save_count is None:
Expand Down
30 changes: 15 additions & 15 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
unicode_literals)

import six
from six.moves import xrange, zip, zip_longest
from six.moves import zip, zip_longest

import functools
import itertools
Expand Down Expand Up @@ -3923,7 +3923,7 @@ def dopatch(xs, ys, **kwargs):
else:
def doplot(*args, **kwargs):
shuffled = []
for i in xrange(0, len(args), 2):
for i in range(0, len(args), 2):
shuffled.extend([args[i + 1], args[i]])
return self.plot(*shuffled, **kwargs)

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

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

# create accumulation arrays
lattice1 = np.empty((nx1, ny1), dtype=object)
for i in xrange(nx1):
for j in xrange(ny1):
for i in range(nx1):
for j in range(ny1):
lattice1[i, j] = []
lattice2 = np.empty((nx2, ny2), dtype=object)
for i in xrange(nx2):
for j in xrange(ny2):
for i in range(nx2):
for j in range(ny2):
lattice2[i, j] = []

for i in xrange(len(x)):
for i in range(len(x)):
if bdist[i]:
if 0 <= ix1[i] < nx1 and 0 <= iy1[i] < ny1:
lattice1[ix1[i], iy1[i]].append(C[i])
else:
if 0 <= ix2[i] < nx2 and 0 <= iy2[i] < ny2:
lattice2[ix2[i], iy2[i]].append(C[i])

for i in xrange(nx1):
for j in xrange(ny1):
for i in range(nx1):
for j in range(ny1):
vals = lattice1[i, j]
if len(vals) > mincnt:
lattice1[i, j] = reduce_C_function(vals)
else:
lattice1[i, j] = np.nan
for i in xrange(nx2):
for j in xrange(ny2):
for i in range(nx2):
for j in range(ny2):
vals = lattice2[i, j]
if len(vals) > mincnt:
lattice2[i, j] = reduce_C_function(vals)
Expand Down Expand Up @@ -6410,7 +6410,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
"""
# Avoid shadowing the builtin.
bin_range = range
del range
from builtins import range

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

if color is None:
color = [self._get_lines.get_next_color() for i in xrange(nx)]
color = [self._get_lines.get_next_color() for i in range(nx)]
else:
color = mcolors.to_rgba_array(color)
if len(color) != nx:
Expand All @@ -6507,7 +6507,7 @@ def hist(self, x, bins=None, range=None, density=None, weights=None,
tops = []
mlast = None
# Loop through datasets
for i in xrange(nx):
for i in range(nx):
# this will automatically overwrite bins,
# so that each histogram uses the same bins
m, bins = np.histogram(x[i], bins, weights=w[i], **hist_kwargs)
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from collections import OrderedDict

import six
from six.moves import xrange

import itertools
import warnings
Expand Down Expand Up @@ -393,7 +392,7 @@ def _plot_args(self, tup, kwargs):
if ncx > 1 and ncy > 1 and ncx != ncy:
cbook.warn_deprecated("2.2", "cycling among columns of inputs "
"with non-matching shapes is deprecated.")
for j in xrange(max(ncx, ncy)):
for j in range(max(ncx, ncy)):
seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
ret.append(seg)
return ret
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
unicode_literals)

import six
from six.moves import xrange

from contextlib import contextmanager
from functools import partial
Expand Down Expand Up @@ -440,7 +439,7 @@ def _iter_collection_raw_paths(self, master_transform, paths,
return

transform = transforms.IdentityTransform()
for i in xrange(N):
for i in range(N):
path = paths[i % Npaths]
if Ntransforms:
transform = Affine2D(all_transforms[i % Ntransforms])
Expand Down Expand Up @@ -518,7 +517,7 @@ def _iter_collection(self, gc, master_transform, all_transforms,
gc0.set_linewidth(0.0)

xo, yo = 0, 0
for i in xrange(N):
for i in range(N):
path_id = path_ids[i % Npaths]
if Noffsets:
xo, yo = toffsets[i % Noffsets]
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/backends/backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import six
from six import unichr
from six.moves import xrange

import base64
import codecs
Expand Down Expand Up @@ -1112,7 +1111,7 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None):
same_y = True
if len(chars) > 1:
last_y = chars[0][1]
for i in xrange(1, len(chars)):
for i in range(1, len(chars)):
if chars[i][1] != last_y:
same_y = False
break
Expand Down
4 changes: 1 addition & 3 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
unicode_literals)

import six
from six.moves import xrange
import six

import sys
import os
Expand Down Expand Up @@ -1448,7 +1446,7 @@ def updateAxes(self, maxAxis):
for menuId in self._axisId[maxAxis:]:
self._menu.Delete(menuId)
self._axisId = self._axisId[:maxAxis]
self._toolbar.set_active(list(xrange(maxAxis)))
self._toolbar.set_active(list(range(maxAxis)))

def getActiveAxes(self):
"""Return a list of the selected axes."""
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,9 +498,9 @@ def _edges(self, X, Y):
# Using the non-array form of these line segments is much
# simpler than making them into arrays.
if self.orientation == 'vertical':
return [list(zip(X[i], Y[i])) for i in xrange(1, N - 1)]
return [list(zip(X[i], Y[i])) for i in range(1, N - 1)]
else:
return [list(zip(Y[i], X[i])) for i in xrange(1, N - 1)]
return [list(zip(Y[i], X[i])) for i in range(1, N - 1)]

def _add_solids(self, X, Y, C):
'''
Expand Down Expand Up @@ -1337,7 +1337,7 @@ def _add_solids(self, X, Y, C):
hatches = self.mappable.hatches * n_segments

patches = []
for i in xrange(len(X) - 1):
for i in range(len(X) - 1):
val = C[i][0]
hatch = hatches[i]

Expand Down
7 changes: 3 additions & 4 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
unicode_literals)

import six
from six.moves import xrange

import warnings
import matplotlib as mpl
Expand Down Expand Up @@ -164,7 +163,7 @@ def clabel(self, *args, **kwargs):
self.rightside_up = kwargs.get('rightside_up', True)
if len(args) == 0:
levels = self.levels
indices = list(xrange(len(self.cvalues)))
indices = list(range(len(self.cvalues)))
elif len(args) == 1:
levlabs = list(args[0])
indices, levels = [], []
Expand All @@ -190,7 +189,7 @@ def clabel(self, *args, **kwargs):
self.labelCValueList = np.take(self.cvalues, self.labelIndiceList)
else:
cmap = colors.ListedColormap(_colors, N=len(self.labelLevelList))
self.labelCValueList = list(xrange(len(self.labelLevelList)))
self.labelCValueList = list(range(len(self.labelLevelList)))
self.labelMappable = cm.ScalarMappable(cmap=cmap,
norm=colors.NoNorm())

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

if indices is None:
indices = list(xrange(len(self.levels)))
indices = list(range(len(self.levels)))

dmin = np.inf
conmin = None
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/hatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
unicode_literals)

import six
from six.moves import xrange

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

cursor = 0
for row in xrange(self.num_rows + 1):
for row in range(self.num_rows + 1):
if row % 2 == 0:
cols = np.linspace(0.0, 1.0, self.num_rows + 1, True)
else:
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
unicode_literals)

import six
from six.moves import xrange

from collections import Sized
from numbers import Number
Expand All @@ -101,7 +100,7 @@
# special-purpose marker identifiers:
(TICKLEFT, TICKRIGHT, TICKUP, TICKDOWN,
CARETLEFT, CARETRIGHT, CARETUP, CARETDOWN,
CARETLEFTBASE, CARETRIGHTBASE, CARETUPBASE, CARETDOWNBASE) = xrange(12)
CARETLEFTBASE, CARETRIGHTBASE, CARETUPBASE, CARETDOWNBASE) = range(12)

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

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
unicode_literals)

import six
from six.moves import map, xrange, zip
from six.moves import map, zip

import copy
import csv
Expand Down Expand Up @@ -1453,7 +1453,7 @@ def cohere_pairs(X, ij, NFFT=256, Fs=2, detrend=detrend_none,
windowVals = window
else:
windowVals = window(np.ones(NFFT, X.dtype))
ind = list(xrange(0, numRows-NFFT+1, NFFT-noverlap))
ind = list(range(0, numRows-NFFT+1, NFFT-noverlap))
numSlices = len(ind)
FFTSlices = {}
FFTConjSlices = {}
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
unicode_literals)

import six
from six.moves import xrange, zip
from six.moves import zip

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

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

anchor_coefs = {UR: "NE",
UL: "NW",
Expand Down
5 changes: 1 addition & 4 deletions lib/matplotlib/stackplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import six
from six.moves import xrange

from cycler import cycler
import numpy as np

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

# Color between array i-1 and array i
for i in xrange(len(y) - 1):
for i in range(len(y) - 1):
color = axes._get_lines.get_next_color()
r.append(axes.fill_between(x, stack[i, :], stack[i + 1, :],
facecolor=color, label=next(labels, None),
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
unicode_literals)

import six
from six.moves import xrange

import numpy as np
import matplotlib
Expand Down Expand Up @@ -648,7 +647,7 @@ def _gen_starting_points(shape):
x, y = 0, 0
i = 0
direction = 'right'
for i in xrange(nx * ny):
for i in range(nx * ny):

yield x, y

Expand Down
11 changes: 5 additions & 6 deletions lib/matplotlib/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
unicode_literals)

import six
from six.moves import xrange

import warnings

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

# Add the cells
for row in xrange(rows):
for col in xrange(cols):
for row in range(rows):
for col in range(cols):
table.add_cell(row + offset, col,
width=colWidths[col], height=height,
text=cellText[row][col],
facecolor=cellColours[row][col],
loc=cellLoc)
# Do column labels
if colLabels is not None:
for col in xrange(cols):
for col in range(cols):
table.add_cell(0, col,
width=colWidths[col], height=height,
text=colLabels[col], facecolor=colColours[col],
loc=colLoc)

# Do row labels
if rowLabels is not None:
for row in xrange(rows):
for row in range(rows):
table.add_cell(row + offset, -1,
width=rowLabelWidth or 1e-15, height=height,
text=rowLabels[row], facecolor=rowColours[row],
Expand Down
Loading