diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-03-28 07:10:01 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-03-28 07:10:01 -0700 |
commit | 40742184df68fc01f3392c9865f35d5402e74b01 (patch) | |
tree | 4d4832417a28e128ed989fc273d322a551d1cfdb /numpy/core | |
parent | db75eb44a31fe1bb04a0f673fd459614bfd02b85 (diff) | |
parent | b995d00e2e54bc6ff97f21bd179d1fc4dc3c92cb (diff) | |
download | numpy-40742184df68fc01f3392c9865f35d5402e74b01.tar.gz |
Merge pull request #3122 from charris/2to3-apply-xrange-fixer
2to3: Replace xrange by range and use list(range(...)) where needed
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/_internal.py | 2 | ||||
-rw-r--r-- | numpy/core/_methods.py | 2 | ||||
-rw-r--r-- | numpy/core/arrayprint.py | 8 | ||||
-rw-r--r-- | numpy/core/code_generators/genapi.py | 2 | ||||
-rw-r--r-- | numpy/core/machar.py | 16 | ||||
-rw-r--r-- | numpy/core/numeric.py | 8 | ||||
-rw-r--r-- | numpy/core/numerictypes.py | 2 | ||||
-rw-r--r-- | numpy/core/records.py | 4 | ||||
-rw-r--r-- | numpy/core/tests/test_blasdot.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_item_selection.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 22 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray_assignment.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_nditer.py | 26 | ||||
-rw-r--r-- | numpy/core/tests/test_numeric.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_records.py | 6 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 16 | ||||
-rw-r--r-- | numpy/core/tests/test_shape_base.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_umath_complex.py | 4 |
19 files changed, 65 insertions, 65 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py index 7ba28f993..6b448528e 100644 --- a/numpy/core/_internal.py +++ b/numpy/core/_internal.py @@ -414,7 +414,7 @@ def _dtype_from_pep3118(spec, byteorder='@', is_subdtype=False): itemsize = 1 if spec[0].isdigit(): j = 1 - for j in xrange(1, len(spec)): + for j in range(1, len(spec)): if not spec[j].isdigit(): break itemsize = int(spec[:j]) diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py index a7f9ccd44..e0eaecb95 100644 --- a/numpy/core/_methods.py +++ b/numpy/core/_methods.py @@ -35,7 +35,7 @@ def _all(a, axis=None, dtype=None, out=None, keepdims=False): def _count_reduce_items(arr, axis): if axis is None: - axis = tuple(xrange(arr.ndim)) + axis = tuple(range(arr.ndim)) if not isinstance(axis, tuple): axis = (axis,) items = 1 diff --git a/numpy/core/arrayprint.py b/numpy/core/arrayprint.py index fa91a4799..c665cec0e 100644 --- a/numpy/core/arrayprint.py +++ b/numpy/core/arrayprint.py @@ -480,14 +480,14 @@ def _formatArray(a, format_function, rank, max_line_len, if rank == 1: s = "" line = next_line_prefix - for i in xrange(leading_items): + for i in range(leading_items): word = format_function(a[i]) + separator s, line = _extendLine(s, line, word, max_line_len, next_line_prefix) if summary_insert1: s, line = _extendLine(s, line, summary_insert1, max_line_len, next_line_prefix) - for i in xrange(trailing_items, 1, -1): + for i in range(trailing_items, 1, -1): word = format_function(a[-i]) + separator s, line = _extendLine(s, line, word, max_line_len, next_line_prefix) @@ -498,7 +498,7 @@ def _formatArray(a, format_function, rank, max_line_len, else: s = '[' sep = separator.rstrip() - for i in xrange(leading_items): + for i in range(leading_items): if i > 0: s += next_line_prefix s += _formatArray(a[i], format_function, rank-1, max_line_len, @@ -509,7 +509,7 @@ def _formatArray(a, format_function, rank, max_line_len, if summary_insert1: s += next_line_prefix + summary_insert1 + "\n" - for i in xrange(trailing_items, 1, -1): + for i in range(trailing_items, 1, -1): if leading_items or i != trailing_items: s += next_line_prefix s += _formatArray(a[-i], format_function, rank-1, max_line_len, diff --git a/numpy/core/code_generators/genapi.py b/numpy/core/code_generators/genapi.py index 164232e6e..a1fb9e641 100644 --- a/numpy/core/code_generators/genapi.py +++ b/numpy/core/code_generators/genapi.py @@ -203,7 +203,7 @@ def find_functions(filename, tag='API'): function_name = None function_args = [] doclist = [] - SCANNING, STATE_DOC, STATE_RETTYPE, STATE_NAME, STATE_ARGS = range(5) + SCANNING, STATE_DOC, STATE_RETTYPE, STATE_NAME, STATE_ARGS = list(range(5)) state = SCANNING tagcomment = '/*' + tag for lineno, line in enumerate(fo): diff --git a/numpy/core/machar.py b/numpy/core/machar.py index b7e64290e..d44d17499 100644 --- a/numpy/core/machar.py +++ b/numpy/core/machar.py @@ -123,7 +123,7 @@ class MachAr(object): # Do we really need to do this? Aren't they 2 and 2.0? # Determine ibeta and beta a = one - for _ in xrange(max_iterN): + for _ in range(max_iterN): a = a + a temp = a + one temp1 = temp - a @@ -132,7 +132,7 @@ class MachAr(object): else: raise RuntimeError(msg % (_, one.dtype)) b = one - for _ in xrange(max_iterN): + for _ in range(max_iterN): b = b + b temp = a + b itemp = int_conv(temp-a) @@ -146,7 +146,7 @@ class MachAr(object): # Determine it and irnd it = -1 b = one - for _ in xrange(max_iterN): + for _ in range(max_iterN): it = it + 1 b = b * beta temp = b + one @@ -158,7 +158,7 @@ class MachAr(object): betah = beta / two a = one - for _ in xrange(max_iterN): + for _ in range(max_iterN): a = a + a temp = a + one temp1 = temp - a @@ -182,7 +182,7 @@ class MachAr(object): for i in range(negep): a = a * betain b = a - for _ in xrange(max_iterN): + for _ in range(max_iterN): temp = one - a if any(temp-one != zero): break @@ -201,7 +201,7 @@ class MachAr(object): machep = - it - 3 a = b - for _ in xrange(max_iterN): + for _ in range(max_iterN): temp = one + a if any(temp-one != zero): break @@ -223,7 +223,7 @@ class MachAr(object): z = betain t = one + eps nxres = 0 - for _ in xrange(max_iterN): + for _ in range(max_iterN): y = z z = y*y a = z*one # Check here for underflow @@ -249,7 +249,7 @@ class MachAr(object): mx = iz + iz - 1 # Determine minexp and xmin - for _ in xrange(max_iterN): + for _ in range(max_iterN): xmin = y y = y * betain a = y * one diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index a114e4bb5..57e366efb 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1040,8 +1040,8 @@ def tensordot(a, b, axes=2): try: iter(axes) except: - axes_a = range(-axes,0) - axes_b = range(0,axes) + axes_a = list(range(-axes,0)) + axes_b = list(range(0,axes)) else: axes_a, axes_b = axes try: @@ -1065,7 +1065,7 @@ def tensordot(a, b, axes=2): equal = True if (na != nb): equal = False else: - for k in xrange(na): + for k in range(na): if as_[axes_a[k]] != bs[axes_b[k]]: equal = False break @@ -1213,7 +1213,7 @@ def rollaxis(a, axis, start=0): start -= 1 if axis==start: return a - axes = range(0,n) + axes = list(range(0,n)) axes.remove(axis) axes.insert(start, axis) return a.transpose(axes) diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py index b069b5426..f89fa994d 100644 --- a/numpy/core/numerictypes.py +++ b/numpy/core/numerictypes.py @@ -112,7 +112,7 @@ if sys.version_info[0] >= 3: # "import string" is costly to import! # Construct the translation tables directly # "A" = chr(65), "a" = chr(97) -_all_chars = map(chr, range(256)) +_all_chars = map(chr, list(range(256))) _ascii_upper = _all_chars[65:65+26] _ascii_lower = _all_chars[97:97+26] LOWER_TABLE="".join(_all_chars[:65] + _ascii_lower + _all_chars[65+26:]) diff --git a/numpy/core/records.py b/numpy/core/records.py index ff5d98d3a..761b1015a 100644 --- a/numpy/core/records.py +++ b/numpy/core/records.py @@ -603,7 +603,7 @@ def fromrecords(recList, dtype=None, shape=None, formats=None, names=None, nfields = len(recList[0]) if formats is None and dtype is None: # slower obj = sb.array(recList, dtype=object) - arrlist = [sb.array(obj[..., i].tolist()) for i in xrange(nfields)] + arrlist = [sb.array(obj[..., i].tolist()) for i in range(nfields)] return fromarrays(arrlist, formats=formats, shape=shape, names=names, titles=titles, aligned=aligned, byteorder=byteorder) @@ -622,7 +622,7 @@ def fromrecords(recList, dtype=None, shape=None, formats=None, names=None, if len(shape) > 1: raise ValueError("Can only deal with 1-d array.") _array = recarray(shape, descr) - for k in xrange(_array.size): + for k in range(_array.size): _array[k] = tuple(recList[k]) return _array else: diff --git a/numpy/core/tests/test_blasdot.py b/numpy/core/tests/test_blasdot.py index ec80840c5..d6abacfc1 100644 --- a/numpy/core/tests/test_blasdot.py +++ b/numpy/core/tests/test_blasdot.py @@ -49,7 +49,7 @@ def test_dot_3args(): v = np.random.random_sample((16, 32)) r = np.empty((1024, 32)) - for i in xrange(12): + for i in range(12): np.dot(f,v,r) assert_equal(sys.getrefcount(r), 2) r2 = np.dot(f,v,out=None) diff --git a/numpy/core/tests/test_item_selection.py b/numpy/core/tests/test_item_selection.py index 6da27175b..ab10b476c 100644 --- a/numpy/core/tests/test_item_selection.py +++ b/numpy/core/tests/test_item_selection.py @@ -47,7 +47,7 @@ class TestTake(TestCase): def test_refcounting(self): - objects = [object() for i in xrange(10)] + objects = [object() for i in range(10)] for mode in ('raise', 'clip', 'wrap'): a = np.array(objects) b = np.array([2, 2, 4, 5, 3, 5]) diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 25cc8ced8..a9a79d38c 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -579,7 +579,7 @@ class TestMethods(TestCase): # test object array sorts. a = np.empty((101,), dtype=np.object) - a[:] = range(101) + a[:] = list(range(101)) b = a[::-1] for kind in ['q', 'h', 'm'] : msg = "object sort, kind=%s" % kind @@ -729,7 +729,7 @@ class TestMethods(TestCase): # test object array argsorts. a = np.empty((101,), dtype=np.object) - a[:] = range(101) + a[:] = list(range(101)) b = a[::-1] r = np.arange(101) rr = r[::-1] @@ -1059,7 +1059,7 @@ class TestMethods(TestCase): # Regression test for a bug that crept in at one point a = np.zeros((100, 100)) assert_(sys.getrefcount(a) < 50) - for i in xrange(100): + for i in range(100): a.diagonal() assert_(sys.getrefcount(a) < 50) @@ -1311,10 +1311,10 @@ class TestArgmax(TestCase): def test_all(self): a = np.random.normal(0,1,(4,5,6,7,8)) - for i in xrange(a.ndim): + for i in range(a.ndim): amax = a.max(i) aargmax = a.argmax(i) - axes = range(a.ndim) + axes = list(range(a.ndim)) axes.remove(i) assert_(all(amax == aargmax.choose(*a.transpose(i,*axes)))) @@ -1379,10 +1379,10 @@ class TestArgmin(TestCase): def test_all(self): a = np.random.normal(0,1,(4,5,6,7,8)) - for i in xrange(a.ndim): + for i in range(a.ndim): amin = a.min(i) aargmin = a.argmin(i) - axes = range(a.ndim) + axes = list(range(a.ndim)) axes.remove(i) assert_(all(amin == aargmin.choose(*a.transpose(i,*axes)))) @@ -1541,7 +1541,7 @@ class TestPutmask(object): class TestTake(object): def tst_basic(self,x): - ind = range(x.shape[0]) + ind = list(range(x.shape[0])) assert_array_equal(x.take(ind, axis=0), x) def test_ip_types(self): @@ -2109,7 +2109,7 @@ class TestDot(TestCase): v = np.random.random_sample((16, 32)) r = np.empty((1024, 32)) - for i in xrange(12): + for i in range(12): dot(f,v,r) assert_equal(sys.getrefcount(r), 2) r2 = dot(f,v,out=None) @@ -2532,7 +2532,7 @@ if sys.version_info >= (2, 6): def test_native_padding(self): align = np.dtype('i').alignment - for j in xrange(8): + for j in range(8): if j == 0: s = 'bi' else: @@ -2793,7 +2793,7 @@ if sys.version_info >= (2, 6): assert_equal(y.format, '<i') def test_padding(self): - for j in xrange(8): + for j in range(8): x = np.array([(1,),(2,)], dtype={'f0': (int, j)}) self._check_roundtrip(x) diff --git a/numpy/core/tests/test_multiarray_assignment.py b/numpy/core/tests/test_multiarray_assignment.py index 555de8c4a..d5e506249 100644 --- a/numpy/core/tests/test_multiarray_assignment.py +++ b/numpy/core/tests/test_multiarray_assignment.py @@ -45,7 +45,7 @@ def _indices(ndims): # no itertools.product available in Py2.4 res = [[]] - for i in xrange(ndims): + for i in range(ndims): newres = [] for elem in ind: for others in res: diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py index d537e4921..219629191 100644 --- a/numpy/core/tests/test_nditer.py +++ b/numpy/core/tests/test_nditer.py @@ -1435,32 +1435,32 @@ def test_iter_iterindex(): a = arange(24).reshape(4,3,2) for flags in ([], ['buffered']): i = nditer(a, flags, buffersize=buffersize) - assert_equal(iter_iterindices(i), range(24)) + assert_equal(iter_iterindices(i), list(range(24))) i.iterindex = 2 - assert_equal(iter_iterindices(i), range(2,24)) + assert_equal(iter_iterindices(i), list(range(2,24))) i = nditer(a, flags, order='F', buffersize=buffersize) - assert_equal(iter_iterindices(i), range(24)) + assert_equal(iter_iterindices(i), list(range(24))) i.iterindex = 5 - assert_equal(iter_iterindices(i), range(5,24)) + assert_equal(iter_iterindices(i), list(range(5,24))) i = nditer(a[::-1], flags, order='F', buffersize=buffersize) - assert_equal(iter_iterindices(i), range(24)) + assert_equal(iter_iterindices(i), list(range(24))) i.iterindex = 9 - assert_equal(iter_iterindices(i), range(9,24)) + assert_equal(iter_iterindices(i), list(range(9,24))) i = nditer(a[::-1,::-1], flags, order='C', buffersize=buffersize) - assert_equal(iter_iterindices(i), range(24)) + assert_equal(iter_iterindices(i), list(range(24))) i.iterindex = 13 - assert_equal(iter_iterindices(i), range(13,24)) + assert_equal(iter_iterindices(i), list(range(13,24))) i = nditer(a[::1,::-1], flags, buffersize=buffersize) - assert_equal(iter_iterindices(i), range(24)) + assert_equal(iter_iterindices(i), list(range(24))) i.iterindex = 23 - assert_equal(iter_iterindices(i), range(23,24)) + assert_equal(iter_iterindices(i), list(range(23,24))) i.reset() i.iterindex = 2 - assert_equal(iter_iterindices(i), range(2,24)) + assert_equal(iter_iterindices(i), list(range(2,24))) def test_iter_iterrange(): # Make sure getting and resetting the iterrange works @@ -1572,7 +1572,7 @@ def test_iter_buffering_delayed_alloc(): assert_equal(i[0], 0) i[1] = 1 assert_equal(i[0:2], [0,1]) - assert_equal([[x[0][()],x[1][()]] for x in i], zip(range(6), [1]*6)) + assert_equal([[x[0][()],x[1][()]] for x in i], zip(list(range(6)), [1]*6)) def test_iter_buffered_cast_simple(): # Test that buffering can handle a simple cast @@ -1804,7 +1804,7 @@ def test_iter_buffered_cast_subarray(): casting='unsafe', op_dtypes=sdt2) assert_equal(i[0].dtype, np.dtype(sdt2)) - for x, count in zip(i, range(6)): + for x, count in zip(i, list(range(6))): assert_(np.all(x['a'] == count)) # one element -> many -> back (copies it to all) diff --git a/numpy/core/tests/test_numeric.py b/numpy/core/tests/test_numeric.py index 6d0ca4efc..6d3cbe923 100644 --- a/numpy/core/tests/test_numeric.py +++ b/numpy/core/tests/test_numeric.py @@ -520,7 +520,7 @@ class TestTypes(TestCase): class TestFromiter(TestCase): def makegen(self): - for x in xrange(24): + for x in range(24): yield x**2 def test_types(self): diff --git a/numpy/core/tests/test_records.py b/numpy/core/tests/test_records.py index 5c7cba936..57d128b11 100644 --- a/numpy/core/tests/test_records.py +++ b/numpy/core/tests/test_records.py @@ -54,11 +54,11 @@ class TestFromrecords(TestCase): b = np.zeros(count, dtype='f8') c = np.zeros(count, dtype='f8') for i in range(len(a)): - a[i] = range(1, 10) + a[i] = list(range(1, 10)) mine = np.rec.fromarrays([a, b, c], names='date,data1,data2') for i in range(len(a)): - assert_((mine.date[i] == range(1, 10))) + assert_((mine.date[i] == list(range(1, 10)))) assert_((mine.data1[i] == 0.0)) assert_((mine.data2[i] == 0.0)) @@ -81,7 +81,7 @@ class TestFromrecords(TestCase): names='c1, c2, c3, c4') assert_(ra.dtype == pa.dtype) assert_(ra.shape == pa.shape) - for k in xrange(len(ra)): + for k in range(len(ra)): assert_(ra[k].item() == pa[k].item()) def test_recarray_conflict_fields(self): diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index 95df4a113..69138647e 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -240,7 +240,7 @@ class TestRegression(TestCase): def test_argmax(self,level=rlevel): """Ticket #119""" a = np.random.normal(0,1,(4,5,6,7,8)) - for i in xrange(a.ndim): + for i in range(a.ndim): aargmax = a.argmax(i) def test_mem_divmod(self,level=rlevel): @@ -675,7 +675,7 @@ class TestRegression(TestCase): def test_arr_transpose(self, level=rlevel): """Ticket #516""" x = np.random.rand(*(2,)*16) - y = x.transpose(range(16)) + y = x.transpose(list(range(16))) def test_string_mergesort(self, level=rlevel): """Ticket #540""" @@ -1188,7 +1188,7 @@ class TestRegression(TestCase): """Ticket #950""" for m in [0, 1, 2]: for n in [0, 1, 2]: - for k in xrange(3): + for k in range(3): # Try to ensure that x->data contains non-zero floats x = np.array([123456789e199], dtype=np.float64) x.resize((m, 0)) @@ -1229,8 +1229,8 @@ class TestRegression(TestCase): def test_fromiter_bytes(self): """Ticket #1058""" - a = np.fromiter(range(10), dtype='b') - b = np.fromiter(range(10), dtype='B') + a = np.fromiter(list(range(10)), dtype='b') + b = np.fromiter(list(range(10)), dtype='B') assert_(np.alltrue(a == np.array([0,1,2,3,4,5,6,7,8,9]))) assert_(np.alltrue(b == np.array([0,1,2,3,4,5,6,7,8,9]))) @@ -1413,8 +1413,8 @@ class TestRegression(TestCase): assert_(np.isfinite(np.log1p(np.exp2(-53)))) def test_fromiter_comparison(self, level=rlevel): - a = np.fromiter(range(10), dtype='b') - b = np.fromiter(range(10), dtype='B') + a = np.fromiter(list(range(10)), dtype='b') + b = np.fromiter(list(range(10)), dtype='B') assert_(np.alltrue(a == np.array([0,1,2,3,4,5,6,7,8,9]))) assert_(np.alltrue(b == np.array([0,1,2,3,4,5,6,7,8,9]))) @@ -1550,7 +1550,7 @@ class TestRegression(TestCase): assert_equal(int(np.uint64(x)), x) def test_duplicate_field_names_assign(self): - ra = np.fromiter(((i*3, i*2) for i in xrange(10)), dtype='i8,f8') + ra = np.fromiter(((i*3, i*2) for i in range(10)), dtype='i8,f8') ra.dtype.names = ('f1', 'f2') rep = repr(ra) # should not cause a segmentation fault assert_raises(ValueError, setattr, ra.dtype, 'names', ('f1', 'f1')) diff --git a/numpy/core/tests/test_shape_base.py b/numpy/core/tests/test_shape_base.py index ccfb18ef7..e0c8197de 100644 --- a/numpy/core/tests/test_shape_base.py +++ b/numpy/core/tests/test_shape_base.py @@ -151,7 +151,7 @@ class TestVstack(TestCase): def test_concatenate_axis_None(): a = np.arange(4, dtype=np.float64).reshape((2,2)) - b = range(3) + b = list(range(3)) c = ['x'] r = np.concatenate((a, a), axis=None) assert_equal(r.dtype, a.dtype) diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index a0fbb4bba..963b2aae7 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -449,7 +449,7 @@ class TestUfunc(TestCase): ret = () base = permute_n(n-1) for perm in base: - for i in xrange(n): + for i in range(n): new = perm + [n-1] new[n-1] = new[i] new[i] = n-1 diff --git a/numpy/core/tests/test_umath_complex.py b/numpy/core/tests/test_umath_complex.py index 9500056bc..34977e683 100644 --- a/numpy/core/tests/test_umath_complex.py +++ b/numpy/core/tests/test_umath_complex.py @@ -400,7 +400,7 @@ class TestCpow(TestCase): def test_scalar(self): x = np.array([1, 1j, 2, 2.5+.37j, np.inf, np.nan]) y = np.array([1, 1j, -0.5+1.5j, -0.5+1.5j, 2, 3]) - lx = range(len(x)) + lx = list(range(len(x))) # Compute the values for complex type in python p_r = [complex(x[i]) ** complex(y[i]) for i in lx] # Substitute a result allowed by C99 standard @@ -413,7 +413,7 @@ class TestCpow(TestCase): def test_array(self): x = np.array([1, 1j, 2, 2.5+.37j, np.inf, np.nan]) y = np.array([1, 1j, -0.5+1.5j, -0.5+1.5j, 2, 3]) - lx = range(len(x)) + lx = list(range(len(x))) # Compute the values for complex type in python p_r = [complex(x[i]) ** complex(y[i]) for i in lx] # Substitute a result allowed by C99 standard |