summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/sphinxext/numpydoc/comment_eater.py2
-rw-r--r--numpy/core/tests/test_nditer.py18
-rw-r--r--numpy/lib/_datasource.py16
-rw-r--r--numpy/lib/index_tricks.py19
-rw-r--r--numpy/lib/npyio.py8
-rw-r--r--numpy/lib/tests/test__datasource.py16
-rw-r--r--numpy/linalg/lapack_lite/fortran.py16
-rw-r--r--numpy/ma/core.py8
-rwxr-xr-xtools/py3tool.py4
9 files changed, 67 insertions, 40 deletions
diff --git a/doc/sphinxext/numpydoc/comment_eater.py b/doc/sphinxext/numpydoc/comment_eater.py
index 8b57c4b7a..8cddd3305 100644
--- a/doc/sphinxext/numpydoc/comment_eater.py
+++ b/doc/sphinxext/numpydoc/comment_eater.py
@@ -106,7 +106,7 @@ class CommentBlocker(object):
def new_comment(self, string, start, end, line):
""" Possibly add a new comment.
-
+
Only adds a new comment if this comment is the only thing on the line.
Otherwise, it extends the noncomment block.
"""
diff --git a/numpy/core/tests/test_nditer.py b/numpy/core/tests/test_nditer.py
index 45fcc2791..31e5a5f10 100644
--- a/numpy/core/tests/test_nditer.py
+++ b/numpy/core/tests/test_nditer.py
@@ -1,12 +1,13 @@
from __future__ import division, absolute_import, print_function
+import sys, warnings
+
import numpy as np
from numpy import array, arange, nditer, all
from numpy.compat import asbytes
from numpy.testing import *
-import sys, warnings
-import warnings
+
def iter_multi_index(i):
ret = []
@@ -1210,7 +1211,8 @@ def test_iter_copy():
assert_equal([x[()] for x in i], [x[()] for x in j])
i.iterrange = (2,18)
- i.next(); i.next()
+ next(i)
+ next(i)
j = i.copy()
assert_equal([x[()] for x in i], [x[()] for x in j])
@@ -2528,14 +2530,14 @@ def test_0d_iter():
# Basic test for iteration of 0-d arrays:
i = nditer([2, 3], ['multi_index'], [['readonly']]*2)
assert_equal(i.ndim, 0)
- assert_equal(i.next(), (2, 3))
+ assert_equal(next(i), (2, 3))
assert_equal(i.multi_index, ())
assert_equal(i.iterindex, 0)
- assert_raises(StopIteration, i.next)
+ assert_raises(StopIteration, next, i)
# test reset:
i.reset()
- assert_equal(i.next(), (2, 3))
- assert_raises(StopIteration, i.next)
+ assert_equal(next(i), (2, 3))
+ assert_raises(StopIteration, next, i)
# test forcing to 0-d
i = nditer(np.arange(5), ['multi_index'], [['readonly']], op_axes=[()])
@@ -2548,7 +2550,7 @@ def test_0d_iter():
a = np.array(0.5, dtype='f4')
i = nditer(a, ['buffered','refs_ok'], ['readonly'],
casting='unsafe', op_dtypes=sdt)
- vals = i.next()
+ vals = next(i)
assert_equal(vals['a'], 0.5)
assert_equal(vals['b'], 0)
assert_equal(vals['c'], [[(0.5)]*3]*2)
diff --git a/numpy/lib/_datasource.py b/numpy/lib/_datasource.py
index 2d35065b0..617acdac1 100644
--- a/numpy/lib/_datasource.py
+++ b/numpy/lib/_datasource.py
@@ -275,8 +275,12 @@ class DataSource (object):
"""
# We import these here because importing urllib2 is slow and
# a significant fraction of numpy's total import time.
- from urllib2 import urlopen
- from urllib2 import URLError
+ if sys.version_info[0] >= 3:
+ from urllib.request import urlopen
+ from urllib.error import URLError
+ else:
+ from urllib2 import urlopen
+ from urllib2 import URLError
upath = self.abspath(path)
@@ -421,8 +425,12 @@ class DataSource (object):
"""
# We import this here because importing urllib2 is slow and
# a significant fraction of numpy's total import time.
- from urllib2 import urlopen
- from urllib2 import URLError
+ if sys.version_info[0] >= 3:
+ from urllib.request import urlopen
+ from urllib.error import URLError
+ else:
+ from urllib2 import urlopen
+ from urllib2 import URLError
# Test local path
if os.path.exists(path):
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:])
diff --git a/numpy/lib/tests/test__datasource.py b/numpy/lib/tests/test__datasource.py
index 3933fdcde..8d3e32b1b 100644
--- a/numpy/lib/tests/test__datasource.py
+++ b/numpy/lib/tests/test__datasource.py
@@ -1,20 +1,21 @@
from __future__ import division, absolute_import, print_function
import os
-import urllib2
import sys
import numpy.lib._datasource as datasource
from tempfile import mkdtemp, mkstemp, NamedTemporaryFile
from shutil import rmtree
-from urllib2 import URLError
from numpy.compat import asbytes
from numpy.testing import *
-
if sys.version_info[0] >= 3:
+ import urllib.request as urllib_request
from urllib.parse import urlparse
+ from urllib.error import URLError
else:
+ import urllib2 as urllib_request
from urlparse import urlparse
+ from urllib2 import URLError
def urlopen_stub(url, data=None):
'''Stub to replace urlopen for testing.'''
@@ -24,14 +25,17 @@ def urlopen_stub(url, data=None):
else:
raise URLError('Name or service not known')
+# setup and teardown
old_urlopen = None
+
def setup():
global old_urlopen
- old_urlopen = urllib2.urlopen
- urllib2.urlopen = urlopen_stub
+
+ old_urlopen = urllib_request.urlopen
+ urllib_request.urlopen = urlopen_stub
def teardown():
- urllib2.urlopen = old_urlopen
+ urllib_request.urlopen = old_urlopen
# A valid website for more robust testing
http_path = 'http://www.google.com/'
diff --git a/numpy/linalg/lapack_lite/fortran.py b/numpy/linalg/lapack_lite/fortran.py
index ce63b0990..3b6ac70f0 100644
--- a/numpy/linalg/lapack_lite/fortran.py
+++ b/numpy/linalg/lapack_lite/fortran.py
@@ -36,14 +36,19 @@ class LineIterator(object):
object.__init__(self)
self.iterable = iter(iterable)
self.lineno = 0
+
def __iter__(self):
return self
- def next(self):
+
+ def __next__(self):
self.lineno += 1
- line = self.iterable.next()
+ line = next(self.iterable)
line = line.rstrip()
return line
+ next = __next__
+
+
class PushbackIterator(object):
"""PushbackIterator(iterable)
@@ -59,15 +64,18 @@ class PushbackIterator(object):
def __iter__(self):
return self
- def next(self):
+ def __next__(self):
if self.buffer:
return self.buffer.pop()
else:
- return self.iterable.next()
+ return next(self.iterable)
def pushback(self, item):
self.buffer.append(item)
+ next = __next__
+
+
def fortranSourceLines(fo):
"""Return an iterator over statement lines of a Fortran source file.
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index fda5e86dc..e1e848206 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -2540,7 +2540,7 @@ class MaskedIterator(object):
if self.maskiter is not None:
self.maskiter[index] = getmaskarray(value)
- def next(self):
+ def __next__(self):
"""
Return the next value, or raise StopIteration.
@@ -2562,12 +2562,12 @@ class MaskedIterator(object):
StopIteration
"""
- d = self.dataiter.next()
- if self.maskiter is not None and self.maskiter.next():
+ d = next(self.dataiter)
+ if self.maskiter is not None and next(self.maskiter):
d = masked
return d
-
+ next = __next__
class MaskedArray(ndarray):
diff --git a/tools/py3tool.py b/tools/py3tool.py
index a6fd5b3f4..072b593a7 100755
--- a/tools/py3tool.py
+++ b/tools/py3tool.py
@@ -72,7 +72,7 @@ FIXES_TO_SKIP = [
'metaclass',
'methodattrs',
'ne',
-# 'next',
+ 'next',
'nonzero',
'numliterals',
'operator',
@@ -90,7 +90,7 @@ FIXES_TO_SKIP = [
'tuple_params',
# 'types',
# 'unicode',
-# 'urllib',
+ 'urllib',
# 'ws_comma',
'xrange',
'xreadlines',