diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-02-23 13:27:05 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-02-23 13:42:27 +0000 |
commit | 6a63d989007c97b85fd1e7119deb265fed4ef8c2 (patch) | |
tree | a74fb8b90b4a9c1c3c22c0f5b2afd5dac6a9edf5 /numpy/lib/recfunctions.py | |
parent | 2aabeafb97bea4e1bfa29d946fbf31e1104e7ae0 (diff) | |
download | numpy-6a63d989007c97b85fd1e7119deb265fed4ef8c2.tar.gz |
MAINT: We can now rely on itertools.izip_longest existing
Diffstat (limited to 'numpy/lib/recfunctions.py')
-rw-r--r-- | numpy/lib/recfunctions.py | 22 |
1 files changed, 9 insertions, 13 deletions
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): |