diff options
author | Julian Taylor <juliantaylor108@gmail.com> | 2017-02-23 15:22:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-23 15:22:26 +0100 |
commit | ddf8d9d8b6c521df8cba9edb3a101e9686c684af (patch) | |
tree | 8afa7e46730b3f61de39eebe922b11e735455031 /numpy/lib/recfunctions.py | |
parent | f6fe0239599f7846168a01f9f64ea74e39c49236 (diff) | |
parent | 6a63d989007c97b85fd1e7119deb265fed4ef8c2 (diff) | |
download | numpy-ddf8d9d8b6c521df8cba9edb3a101e9686c684af.tar.gz |
Merge pull request #8677 from eric-wieser/use-izip_longest
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): |