summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-04-06 19:09:17 -0600
committerCharles Harris <charlesr.harris@gmail.com>2013-04-06 19:09:17 -0600
commitaab46a78cefe9fbd46104496ffad17667784a3f5 (patch)
tree1385a8433047a5cb92f3dcf3b2af12ca02b0025d /numpy/lib
parent3c70e20a5f1aed4098ba66d21e6a1f60edc6fddd (diff)
downloadnumpy-aab46a78cefe9fbd46104496ffad17667784a3f5.tar.gz
2to3: apply `dict` fixer.
In Python3 `dict.items()`, `dict.keys()`, and `dict.values()` are iterators. This causes problems when a list is needed so the 2to3 fixer explicitly constructs a list when is finds on of those functions. However, that is usually not necessary, so a lot of the work here has been cleaning up those places where the fix is not needed. The big exception to that is the `numpy/f2py/crackfortran.py` file. The code there makes extensive use of loops that modify the contents of the dictionary being looped through, which raises an error. That together with the obscurity of the code in that file made it safest to let the `dict` fixer do its worst. Closes #3050.
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/_datasource.py2
-rw-r--r--numpy/lib/arraypad.py2
-rw-r--r--numpy/lib/format.py2
-rw-r--r--numpy/lib/npyio.py4
-rw-r--r--numpy/lib/recfunctions.py2
-rw-r--r--numpy/lib/tests/test_io.py4
-rw-r--r--numpy/lib/utils.py2
7 files changed, 9 insertions, 9 deletions
diff --git a/numpy/lib/_datasource.py b/numpy/lib/_datasource.py
index 13060593d..2d35065b0 100644
--- a/numpy/lib/_datasource.py
+++ b/numpy/lib/_datasource.py
@@ -104,7 +104,7 @@ class _FileOpeners(object):
"""
self._load()
- return self._file_openers.keys()
+ return list(self._file_openers.keys())
def __getitem__(self, key):
self._load()
return self._file_openers[key]
diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py
index de909bc87..8a7c3a067 100644
--- a/numpy/lib/arraypad.py
+++ b/numpy/lib/arraypad.py
@@ -754,7 +754,7 @@ def pad(array, pad_width, mode=None, **kwargs):
kwargs[i] = _normalize_shape(narray, kwargs[i])
elif mode == None:
raise ValueError('Keyword "mode" must be a function or one of %s.' %
- (modefunc.keys(),))
+ (list(modefunc.keys()),))
else:
# User supplied function, I hope
function = mode
diff --git a/numpy/lib/format.py b/numpy/lib/format.py
index 93d20fa4c..886ba45b3 100644
--- a/numpy/lib/format.py
+++ b/numpy/lib/format.py
@@ -344,7 +344,7 @@ def read_array_header_1_0(fp):
if not isinstance(d, dict):
msg = "Header is not a dictionary: %r"
raise ValueError(msg % d)
- keys = d.keys()
+ keys = list(d.keys())
keys.sort()
if keys != ['descr', 'fortran_order', 'shape']:
msg = "Header does not contain the correct keys: %r"
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index 14d41a3c1..7f66fb141 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -572,7 +572,7 @@ def _savez(file, args, kwds, compress):
fd, tmpfile = tempfile.mkstemp(suffix='-numpy.npy')
os.close(fd)
try:
- for key, val in namedict.iteritems():
+ for key, val in namedict.items():
fname = key + '.npy'
fid = open(tmpfile, 'wb')
try:
@@ -811,7 +811,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
packing = [(N, tuple)]
# By preference, use the converters specified by the user
- for i, conv in (user_converters or {}).iteritems():
+ for i, conv in (user_converters or {}).items():
if usecols:
try:
i = usecols.index(i)
diff --git a/numpy/lib/recfunctions.py b/numpy/lib/recfunctions.py
index b96186bbd..a9f480f5d 100644
--- a/numpy/lib/recfunctions.py
+++ b/numpy/lib/recfunctions.py
@@ -317,7 +317,7 @@ def _fix_defaults(output, defaults=None):
"""
names = output.dtype.names
(data, mask, fill_value) = (output.data, output.mask, output.fill_value)
- for (k, v) in (defaults or {}).iteritems():
+ for (k, v) in (defaults or {}).items():
if k in names:
fill_value[k] = v
data[k][mask[k]] = v
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 43739c53c..af4eed05d 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -1620,7 +1620,7 @@ def test_npzfile_dict():
assert_('x' in z.keys())
assert_('y' in z.keys())
- for f, a in z.iteritems():
+ for f, a in z.items():
assert_(f in ['x', 'y'])
assert_equal(a.shape, (3, 3))
@@ -1629,7 +1629,7 @@ def test_npzfile_dict():
for f in z:
assert_(f in ['x', 'y'])
- assert_('x' in list(z.iterkeys()))
+ assert_('x' in z.keys())
def test_load_refcount():
# Check that objects returned by np.load are directly freed based on
diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py
index 4ed534455..75ba5bca6 100644
--- a/numpy/lib/utils.py
+++ b/numpy/lib/utils.py
@@ -755,7 +755,7 @@ def lookfor(what, module=None, import_modules=True, regenerate=False,
whats = str(what).lower().split()
if not whats: return
- for name, (docstring, kind, index) in cache.iteritems():
+ for name, (docstring, kind, index) in cache.items():
if kind in ('module', 'object'):
# don't show modules or objects
continue