From 6a63d989007c97b85fd1e7119deb265fed4ef8c2 Mon Sep 17 00:00:00 2001 From: Eric Wieser Date: Thu, 23 Feb 2017 13:27:05 +0000 Subject: MAINT: We can now rely on itertools.izip_longest existing --- numpy/lib/recfunctions.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'numpy/lib/recfunctions.py') diff --git a/numpy/lib/recfunctions.py b/numpy/lib/recfunctions.py index 4ae1079d2..d3d58d1f2 100644 --- a/numpy/lib/recfunctions.py +++ b/numpy/lib/recfunctions.py @@ -275,24 +275,20 @@ def izip_records(seqarrays, fill_value=None, flatten=True): flatten : {True, False}, Whether to """ - # OK, that's a complete ripoff from Python2.6 itertools.izip_longest - def sentinel(counter=([fill_value] * (len(seqarrays) - 1)).pop): - "Yields the fill_value or raises IndexError" - yield counter() - # - fillers = itertools.repeat(fill_value) - iters = [itertools.chain(it, sentinel(), fillers) for it in seqarrays] + # Should we flatten the items, or just use a nested approach if flatten: zipfunc = _izip_fields_flat else: zipfunc = _izip_fields - # - try: - for tup in zip(*iters): - yield tuple(zipfunc(tup)) - except IndexError: - pass + + if sys.version_info[0] >= 3: + zip_longest = itertools.zip_longest + else: + zip_longest = itertools.izip_longest + + for tup in zip_longest(*seqarrays, fillvalue=fill_value): + yield tuple(zipfunc(tup)) def _fix_output(output, usemask=True, asrecarray=False): -- cgit v1.2.1