diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-04-13 15:34:26 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-04-13 17:04:13 -0600 |
commit | 0dfe67afd1ee9e4c905bf119673f6e634221f21b (patch) | |
tree | a45a1e39de66d5d462a69040ea7e996cf234a011 /numpy/lib | |
parent | e589c6ed1dac7755bb7bd9e181a43ebeff62dcec (diff) | |
download | numpy-0dfe67afd1ee9e4c905bf119673f6e634221f21b.tar.gz |
2to3: Apply zip fixer.
In Python 3 zip returns an iterator instead of a list. Consequently, in
places where an iterator won't do it must be enclosed in list(...).
Lists instead of iterators are also used in array constructors as using
iterators there usually results in an object array containing an
iterator object.
Closes #3094
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/_iotools.py | 2 | ||||
-rw-r--r-- | numpy/lib/npyio.py | 12 | ||||
-rw-r--r-- | numpy/lib/tests/test_arraysetops.py | 4 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 4 | ||||
-rw-r--r-- | numpy/lib/tests/test_recfunctions.py | 24 |
5 files changed, 23 insertions, 23 deletions
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py index dc143415e..dc7f533a5 100644 --- a/numpy/lib/_iotools.py +++ b/numpy/lib/_iotools.py @@ -855,7 +855,7 @@ def easy_dtype(ndtype, names=None, defaultfmt="f%i", **validationargs): if nbtypes == 0: formats = tuple([ndtype.type] * len(names)) names = validate(names, defaultfmt=defaultfmt) - ndtype = np.dtype(zip(names, formats)) + ndtype = np.dtype(list(zip(names, formats))) # Structured dtype: just validate the names as needed else: ndtype.names = validate(names, nbfields=nbtypes, diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index ea8d98656..19842feec 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -1664,11 +1664,11 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, # rows[i] = tuple([convert(val) # for (convert, val) in zip(conversionfuncs, vals)]) if loose: - rows = zip(*[[converter._loose_call(_r) for _r in map(itemgetter(i), rows)] - for (i, converter) in enumerate(converters)]) + rows = list(zip(*[[converter._loose_call(_r) for _r in map(itemgetter(i), rows)] + for (i, converter) in enumerate(converters)])) else: - rows = zip(*[[converter._strict_call(_r) for _r in map(itemgetter(i), rows)] - for (i, converter) in enumerate(converters)]) + rows = list(zip(*[[converter._strict_call(_r) for _r in map(itemgetter(i), rows)] + for (i, converter) in enumerate(converters)])) # Reset the dtype data = rows if dtype is None: @@ -1693,8 +1693,8 @@ def genfromtxt(fname, dtype=float, comments='#', delimiter=None, mdtype = [(defaultfmt % i, np.bool) for (i, dt) in enumerate(column_types)] else: - ddtype = zip(names, column_types) - mdtype = zip(names, [np.bool] * len(column_types)) + ddtype = list(zip(names, column_types)) + mdtype = list(zip(names, [np.bool] * len(column_types))) output = np.array(data, dtype=ddtype) if usemask: outputmask = np.array(masks, dtype=mdtype) diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py index f7f75922d..4ba6529e4 100644 --- a/numpy/lib/tests/test_arraysetops.py +++ b/numpy/lib/tests/test_arraysetops.py @@ -61,8 +61,8 @@ class TestSetOps(TestCase): # test for structured arrays dt = [('', 'i'), ('', 'i')] - aa = np.array(zip(a,a), dt) - bb = np.array(zip(b,b), dt) + aa = np.array(list(zip(a,a)), dt) + bb = np.array(list(zip(b,b)), dt) check_all(aa, bb, i1, i2, dt) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index af4eed05d..5987a15b0 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -517,7 +517,7 @@ class TestLoadTxt(TestCase): c = TextIO(data) names = ['stid', 'temp'] dtypes = ['S4', 'f8'] - arr = np.loadtxt(c, usecols=(0, 2), dtype=zip(names, dtypes)) + arr = np.loadtxt(c, usecols=(0, 2), dtype=list(zip(names, dtypes))) assert_equal(arr['stid'], [b"JOE", b"BOB"]) assert_equal(arr['temp'], [25.3, 27.9]) @@ -1119,7 +1119,7 @@ M 33 21.99 data = TextIO("JOE 70.1 25.3\nBOB 60.5 27.9") names = ['stid', 'temp'] dtypes = ['S4', 'f8'] - test = np.ndfromtxt(data, usecols=(0, 2), dtype=zip(names, dtypes)) + test = np.ndfromtxt(data, usecols=(0, 2), dtype=list(zip(names, dtypes))) assert_equal(test['stid'], [b"JOE", b"BOB"]) assert_equal(test['temp'], [25.3, 27.9]) diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py index 899031451..ef22ca413 100644 --- a/numpy/lib/tests/test_recfunctions.py +++ b/numpy/lib/tests/test_recfunctions.py @@ -543,11 +543,11 @@ class TestStackArrays(TestCase): class TestJoinBy(TestCase): def setUp(self): - self.a = np.array(zip(np.arange(10), np.arange(50, 60), - np.arange(100, 110)), + self.a = np.array(list(zip(np.arange(10), np.arange(50, 60), + np.arange(100, 110))), dtype=[('a', int), ('b', int), ('c', int)]) - self.b = np.array(zip(np.arange(5, 15), np.arange(65, 75), - np.arange(100, 110)), + self.b = np.array(list(zip(np.arange(5, 15), np.arange(65, 75), + np.arange(100, 110))), dtype=[('a', int), ('b', int), ('d', int)]) # def test_inner_join(self): @@ -620,11 +620,11 @@ class TestJoinBy(TestCase): class TestJoinBy2(TestCase): @classmethod def setUp(cls): - cls.a = np.array(zip(np.arange(10), np.arange(50, 60), - np.arange(100, 110)), + cls.a = np.array(list(zip(np.arange(10), np.arange(50, 60), + np.arange(100, 110))), dtype=[('a', int), ('b', int), ('c', int)]) - cls.b = np.array(zip(np.arange(10), np.arange(65, 75), - np.arange(100, 110)), + cls.b = np.array(list(zip(np.arange(10), np.arange(65, 75), + np.arange(100, 110))), dtype=[('a', int), ('b', int), ('d', int)]) def test_no_r1postfix(self): @@ -660,12 +660,12 @@ class TestJoinBy2(TestCase): assert_equal(test, control) def test_two_keys_two_vars(self): - a = np.array(zip(np.tile([10,11],5),np.repeat(np.arange(5),2), - np.arange(50, 60), np.arange(10,20)), + a = np.array(list(zip(np.tile([10,11],5),np.repeat(np.arange(5),2), + np.arange(50, 60), np.arange(10,20))), dtype=[('k', int), ('a', int), ('b', int),('c',int)]) - b = np.array(zip(np.tile([10,11],5),np.repeat(np.arange(5),2), - np.arange(65, 75), np.arange(0,10)), + b = np.array(list(zip(np.tile([10,11],5),np.repeat(np.arange(5),2), + np.arange(65, 75), np.arange(0,10))), dtype=[('k', int), ('a', int), ('b', int), ('c',int)]) control = np.array([(10, 0, 50, 65, 10, 0), (11, 0, 51, 66, 11, 1), |