diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2019-05-12 00:57:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-12 00:57:53 -0700 |
commit | e6227a0326b503172fa9f95e0544a099ec85e05d (patch) | |
tree | c94fb74a013902ca7e3b19cc06596ab155545dc8 /numpy/lib/format.py | |
parent | 9dad3488e35ae3d26184851a5d7d7a1a171a5857 (diff) | |
parent | bd73a15363295658e150754edf6d1073cbdb3975 (diff) | |
download | numpy-e6227a0326b503172fa9f95e0544a099ec85e05d.tar.gz |
Merge pull request #13433 from mattip/issue13431
BUG: Handle subarrays in descr_to_dtype
Diffstat (limited to 'numpy/lib/format.py')
-rw-r--r-- | numpy/lib/format.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 553c9371d..86f71eda9 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -261,15 +261,19 @@ def dtype_to_descr(dtype): def descr_to_dtype(descr): ''' descr may be stored as dtype.descr, which is a list of - (name, format, [shape]) tuples. Offsets are not explicitly saved, rather - empty fields with name,format == '', '|Vn' are added as padding. + (name, format, [shape]) tuples where format may be a str or a tuple. + Offsets are not explicitly saved, rather empty fields with + name, format == '', '|Vn' are added as padding. This function reverses the process, eliminating the empty padding fields. ''' - if isinstance(descr, (str, dict)): + if isinstance(descr, str): # No padding removal needed return numpy.dtype(descr) - + elif isinstance(descr, tuple): + # subtype, will always have a shape descr[1] + dt = descr_to_dtype(descr[0]) + return numpy.dtype((dt, descr[1])) fields = [] offset = 0 for field in descr: |