diff options
author | Sha Liu <liushapku@users.noreply.github.com> | 2020-01-28 11:30:20 +0800 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2020-01-27 19:30:20 -0800 |
commit | 79eff02e7e2c3b1865ee47fa66ae40f44894cadb (patch) | |
tree | 7a468d5644056d059b9a431983d6ee81e32fd057 /numpy/lib/format.py | |
parent | f398a0df8a2105b2fdeaeab54505451169b0a869 (diff) | |
download | numpy-79eff02e7e2c3b1865ee47fa66ae40f44894cadb.tar.gz |
BUG: np.load does not handle empty array with an empty descr (#15397)
The bug occurs since numpy 1.16. Before that empty descr corresponds to
`np.dtype([])`. This fixes the problem by following numpy 1.15's
behavior.
Closes gh-15396
Diffstat (limited to 'numpy/lib/format.py')
-rw-r--r-- | numpy/lib/format.py | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py index b31340314..e2696c286 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -295,7 +295,11 @@ def descr_to_dtype(descr): # subtype, will always have a shape descr[1] dt = descr_to_dtype(descr[0]) return numpy.dtype((dt, descr[1])) - fields = [] + + titles = [] + names = [] + formats = [] + offsets = [] offset = 0 for field in descr: if len(field) == 2: @@ -309,14 +313,13 @@ def descr_to_dtype(descr): # Once support for blank names is removed, only "if name == ''" needed) is_pad = (name == '' and dt.type is numpy.void and dt.names is None) if not is_pad: - fields.append((name, dt, offset)) - + title, name = name if isinstance(name, tuple) else (None, name) + titles.append(title) + names.append(name) + formats.append(dt) + offsets.append(offset) offset += dt.itemsize - names, formats, offsets = zip(*fields) - # names may be (title, names) tuples - nametups = (n if isinstance(n, tuple) else (None, n) for n in names) - titles, names = zip(*nametups) return numpy.dtype({'names': names, 'formats': formats, 'titles': titles, 'offsets': offsets, 'itemsize': offset}) |