From 666d92ac85a6adf0fec7361c3340fc6ab12c8330 Mon Sep 17 00:00:00 2001 From: mattip Date: Tue, 30 Apr 2019 06:47:29 -0400 Subject: BUG: handle subarrays in descr_to_dtype --- numpy/lib/format.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'numpy/lib/format.py') diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 553c9371d..abd98dd22 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -261,12 +261,13 @@ 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, dict, tuple)): # No padding removal needed return numpy.dtype(descr) -- cgit v1.2.1 From b90addd13f17d967d81dc1d7515887d4fcd6ef59 Mon Sep 17 00:00:00 2001 From: mattip Date: Thu, 2 May 2019 11:29:10 -0400 Subject: BUG: parse more subarrays in descr_to_dtype --- numpy/lib/format.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'numpy/lib/format.py') diff --git a/numpy/lib/format.py b/numpy/lib/format.py index abd98dd22..05fcbc0bc 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -267,10 +267,15 @@ def descr_to_dtype(descr): This function reverses the process, eliminating the empty padding fields. ''' - if isinstance(descr, (str, dict, tuple)): + if isinstance(descr, (str, dict)): # No padding removal needed return numpy.dtype(descr) - + elif isinstance(descr, tuple): + if isinstance(descr[0], list): + # subtype, will always have a shape descr[1] + dt = descr_to_dtype(descr[0]) + return numpy.dtype((dt, descr[1])) + return numpy.dtype(descr) fields = [] offset = 0 for field in descr: -- cgit v1.2.1 From bd73a15363295658e150754edf6d1073cbdb3975 Mon Sep 17 00:00:00 2001 From: mattip Date: Sun, 5 May 2019 19:50:06 -0400 Subject: MAINT: remove uneeded code --- numpy/lib/format.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'numpy/lib/format.py') diff --git a/numpy/lib/format.py b/numpy/lib/format.py index 05fcbc0bc..86f71eda9 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -267,15 +267,13 @@ def descr_to_dtype(descr): 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): - if isinstance(descr[0], list): - # subtype, will always have a shape descr[1] - dt = descr_to_dtype(descr[0]) - return numpy.dtype((dt, descr[1])) - return numpy.dtype(descr) + # 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: -- cgit v1.2.1