summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-04-06 11:46:39 -0600
committerCharles Harris <charlesr.harris@gmail.com>2013-04-15 08:44:49 -0600
commitc6de09799decbb22bb2d7a44036f53c30356edda (patch)
treecdd392afe5ecd5cc185c45b1387c54712e93ca2c /numpy/lib
parent6c47259eec0ec20c1150c2b29994de59a3158964 (diff)
downloadnumpy-c6de09799decbb22bb2d7a44036f53c30356edda.tar.gz
2to3: Apply next fixer.
The next builtin has been available since Python 2.6 and allows `it.next()` to be replaced by `next(it)`. In Python 3 the `next` method is gone entirely, replaced entirely by the `__next__` method. The next fixer changes all the `it.next()` calls to the new form and renames the `next` methods to `__next__`. In order to keep Numpy code backwards compatible with Python 2, a `next` method was readded to all the Numpy iterators after the fixer was run so they all contain both methods. The presence of the appropriate method could have been made version dependent, but that looked unduly complicated. Closes #3072.
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/index_tricks.py19
-rw-r--r--numpy/lib/npyio.py8
2 files changed, 16 insertions, 11 deletions
diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py
index b04e348b8..314cba120 100644
--- a/numpy/lib/index_tricks.py
+++ b/numpy/lib/index_tricks.py
@@ -487,7 +487,7 @@ class ndenumerate(object):
def __init__(self, arr):
self.iter = asarray(arr).flat
- def next(self):
+ def __next__(self):
"""
Standard iterator method, returns the index tuple and array value.
@@ -499,11 +499,14 @@ class ndenumerate(object):
The array element of the current iteration.
"""
- return self.iter.coords, self.iter.next()
+ return self.iter.coords, next(self.iter)
def __iter__(self):
return self
+ next = __next__
+
+
class ndindex(object):
"""
An N-dimensional iterator object to index arrays.
@@ -532,7 +535,7 @@ class ndindex(object):
(2, 0, 0)
(2, 1, 0)
- """
+ """
def __init__(self, *shape):
if len(shape) == 1 and isinstance(shape[0], tuple):
shape = shape[0]
@@ -541,16 +544,16 @@ class ndindex(object):
def __iter__(self):
return self
-
+
def ndincr(self):
"""
Increment the multi-dimensional index by one.
This method is for backward compatibility only: do not use.
"""
- self.next()
+ next(self)
- def next(self):
+ def __next__(self):
"""
Standard iterator method, updates the index and returns the index tuple.
@@ -560,9 +563,11 @@ class ndindex(object):
Returns a tuple containing the indices of the current iteration.
"""
- self._it.next()
+ next(self._it)
return self._it.multi_index
+ next = __next__
+
# You can do all this with slice() plus a few special objects,
# but there's a lot to remember. This version is simpler because
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 733868780..2154acdce 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -785,14 +785,14 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
# Skip the first `skiprows` lines
for i in range(skiprows):
- fh.next()
+ next(fh)
# Read until we find a line with some values, and use
# it to estimate the number of columns, N.
first_vals = None
try:
while not first_vals:
- first_line = fh.next()
+ first_line = next(fh)
first_vals = split_line(first_line)
except StopIteration:
# End of lines reached
@@ -1344,13 +1344,13 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None,
skip_header = skiprows
# Skip the first `skip_header` rows
for i in range(skip_header):
- fhd.next()
+ next(fhd)
# Keep on until we find the first valid values
first_values = None
try:
while not first_values:
- first_line = fhd.next()
+ first_line = next(fhd)
if names is True:
if comments in first_line:
first_line = asbytes('').join(first_line.split(comments)[1:])