From 5de56efaad908f2b731a7eda2b9ca2a9196f820a Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Fri, 12 Apr 2013 20:10:58 -0600 Subject: 2to3: Apply itertools fixer. In Python 3 zip, map, and filter are all iterators, consequently the itertools variants izip, imap, and ifilter have been removed and the itertools fixer replaces them with the unprefixed names. Because the places where the iterator variants are used in current look like places where the iterator version might be useful, the approach taken here is to define the prefixed versions to the unprefixed versions for Python 3, but otherwise import them from itertools. Closes #3233. --- numpy/lib/recfunctions.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'numpy/lib/recfunctions.py') diff --git a/numpy/lib/recfunctions.py b/numpy/lib/recfunctions.py index f909a4838..349d1996e 100644 --- a/numpy/lib/recfunctions.py +++ b/numpy/lib/recfunctions.py @@ -16,6 +16,11 @@ from numpy.ma import MaskedArray from numpy.ma.mrecords import MaskedRecords from numpy.lib._iotools import _is_string_like +if sys.version_info[0] >= 3: + izip = zip +else: + izip = itertools.izip + _check_fill_value = np.ma.core._check_fill_value __all__ = ['append_fields', @@ -287,7 +292,7 @@ def izip_records(seqarrays, fill_value=None, flatten=True): zipfunc = _izip_fields # try: - for tup in itertools.izip(*iters): + for tup in izip(*iters): yield tuple(zipfunc(tup)) except IndexError: pass @@ -412,7 +417,7 @@ def merge_arrays(seqarrays, seqmask = [] # If we expect some kind of MaskedArray, make a special loop. if usemask: - for (a, n) in itertools.izip(seqarrays, sizes): + for (a, n) in izip(seqarrays, sizes): nbmissing = (maxlength - n) # Get the data and mask data = a.ravel().__array__() @@ -441,7 +446,7 @@ def merge_arrays(seqarrays, output = output.view(MaskedRecords) else: # Same as before, without the mask we don't need... - for (a, n) in itertools.izip(seqarrays, sizes): + for (a, n) in izip(seqarrays, sizes): nbmissing = (maxlength - n) data = a.ravel().__array__() if nbmissing: -- cgit v1.2.1