summaryrefslogtreecommitdiff
path: root/numpy/core
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/core
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/core')
-rw-r--r--numpy/core/_internal.py8
-rw-r--r--numpy/core/code_generators/genapi.py4
-rw-r--r--numpy/core/memmap.py2
-rw-r--r--numpy/core/numerictypes.py4
-rw-r--r--numpy/core/tests/test_blasdot.py2
-rw-r--r--numpy/core/tests/test_multiarray.py4
6 files changed, 12 insertions, 12 deletions
diff --git a/numpy/core/_internal.py b/numpy/core/_internal.py
index 5115975c2..292dfb8be 100644
--- a/numpy/core/_internal.py
+++ b/numpy/core/_internal.py
@@ -20,7 +20,7 @@ else:
def _makenames_list(adict, align):
from .multiarray import dtype
allfields = []
- fnames = adict.keys()
+ fnames = list(adict.keys())
for fname in fnames:
obj = adict[fname]
n = len(obj)
@@ -332,7 +332,7 @@ _pep3118_native_map = {
'O': 'O',
'x': 'V', # padding
}
-_pep3118_native_typechars = ''.join(_pep3118_native_map.keys())
+_pep3118_native_typechars = ''.join(list(_pep3118_native_map.keys()))
_pep3118_standard_map = {
'?': '?',
@@ -356,7 +356,7 @@ _pep3118_standard_map = {
'O': 'O',
'x': 'V', # padding
}
-_pep3118_standard_typechars = ''.join(_pep3118_standard_map.keys())
+_pep3118_standard_typechars = ''.join(list(_pep3118_standard_map.keys()))
def _dtype_from_pep3118(spec, byteorder='@', is_subdtype=False):
from numpy.core.multiarray import dtype
@@ -505,7 +505,7 @@ def _dtype_from_pep3118(spec, byteorder='@', is_subdtype=False):
offset += extra_offset
# Check if this was a simple 1-item type
- if len(fields.keys()) == 1 and not explicit_name and fields['f0'][1] == 0 \
+ if len(list(fields.keys())) == 1 and not explicit_name and fields['f0'][1] == 0 \
and not is_subdtype:
ret = fields['f0'][0]
else:
diff --git a/numpy/core/code_generators/genapi.py b/numpy/core/code_generators/genapi.py
index 2f188af17..7fbacae26 100644
--- a/numpy/core/code_generators/genapi.py
+++ b/numpy/core/code_generators/genapi.py
@@ -386,7 +386,7 @@ NPY_NO_EXPORT %s %s \\\n (%s);""" % (self.return_type,
def order_dict(d):
"""Order dict by its values."""
- o = d.items()
+ o = list(d.items())
def _key(x):
return (x[1], x[0])
return sorted(o, key=_key)
@@ -448,7 +448,7 @@ def fullapi_hash(api_dicts):
def sorted_by_values(d):
"""Sort a dictionary by its values. Assume the dictionary items is of
the form func_name -> order"""
- return sorted(d.items(), key=lambda x_y: (x_y[1], x_y[0]))
+ return sorted(list(d.items()), key=lambda x_y: (x_y[1], x_y[0]))
for name, index in sorted_by_values(d):
a.extend(name)
a.extend(str(index))
diff --git a/numpy/core/memmap.py b/numpy/core/memmap.py
index daa4d751a..ee079157d 100644
--- a/numpy/core/memmap.py
+++ b/numpy/core/memmap.py
@@ -201,7 +201,7 @@ class memmap(ndarray):
except KeyError:
if mode not in valid_filemodes:
raise ValueError("mode must be one of %s" %
- (valid_filemodes + mode_equivalents.keys()))
+ (valid_filemodes + list(mode_equivalents.keys())))
if hasattr(filename,'read'):
fid = filename
diff --git a/numpy/core/numerictypes.py b/numpy/core/numerictypes.py
index a7ca5f8f7..43979f71a 100644
--- a/numpy/core/numerictypes.py
+++ b/numpy/core/numerictypes.py
@@ -788,7 +788,7 @@ _alignment = _typedict()
_maxvals = _typedict()
_minvals = _typedict()
def _construct_lookups():
- for name, val in typeinfo.iteritems():
+ for name, val in typeinfo.items():
if not isinstance(val, tuple):
continue
obj = val[-1]
@@ -863,7 +863,7 @@ except AttributeError:
# Py3K
ScalarType = [int, float, complex, long, bool, bytes, str, memoryview]
-ScalarType.extend(_sctype2char_dict.keys())
+ScalarType.extend(list(_sctype2char_dict.keys()))
ScalarType = tuple(ScalarType)
for key in _sctype2char_dict.keys():
cast[key] = lambda x, k=key : array(x, copy=False).astype(k)
diff --git a/numpy/core/tests/test_blasdot.py b/numpy/core/tests/test_blasdot.py
index 21f65b377..fb215296f 100644
--- a/numpy/core/tests/test_blasdot.py
+++ b/numpy/core/tests/test_blasdot.py
@@ -105,7 +105,7 @@ def test_dot_array_order():
dtypes_prec = {np.float64: 7, np.float32: 5}
np.random.seed(7)
- for arr_type, prec in dtypes_prec.iteritems():
+ for arr_type, prec in dtypes_prec.items():
for a_order in orders:
a = np.asarray(np.random.randn(a_dim, a_dim),
dtype=arr_type, order=a_order)
diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py
index fc58f6e9c..746eb73b5 100644
--- a/numpy/core/tests/test_multiarray.py
+++ b/numpy/core/tests/test_multiarray.py
@@ -1502,7 +1502,7 @@ class TestPutmask(object):
mask = x < 40
for val in [-100,0,15]:
- for types in np.sctypes.itervalues():
+ for types in np.sctypes.values():
for T in types:
if T not in unchecked_types:
yield self.tst_basic,x.copy().astype(T),T,mask,val
@@ -1549,7 +1549,7 @@ class TestTake(object):
x = np.random.random(24)*100
x.shape = 2,3,4
- for types in np.sctypes.itervalues():
+ for types in np.sctypes.values():
for T in types:
if T not in unchecked_types:
yield self.tst_basic,x.copy().astype(T)