summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2019-08-16 18:38:26 -0700
committerEric Wieser <wieser.eric@gmail.com>2019-08-19 17:24:58 -0500
commit731127385578fa2cf4e0ad48ef2e456d897d36de (patch)
tree82293572491a42d87f990077d6f217e52be07c67
parent03cd242040120a149615cb2c843636069fa2ff10 (diff)
downloadnumpy-731127385578fa2cf4e0ad48ef2e456d897d36de.tar.gz
BUG: Fix crash on genfromtxt with nested empty structured array
Previously this would fail with `ValueError: could not assign tuple of length 2 to structure with 3 fields.`, now it raises `NotImplementedError`.
-rw-r--r--numpy/lib/_iotools.py2
-rw-r--r--numpy/lib/tests/test_io.py7
2 files changed, 8 insertions, 1 deletions
diff --git a/numpy/lib/_iotools.py b/numpy/lib/_iotools.py
index 8a042f190..04b147b0e 100644
--- a/numpy/lib/_iotools.py
+++ b/numpy/lib/_iotools.py
@@ -121,7 +121,7 @@ def has_nested_fields(ndtype):
"""
for name in ndtype.names or ():
- if ndtype[name].names:
+ if ndtype[name].names is not None:
return True
return False
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 7ef25538b..038d08acf 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -1517,6 +1517,13 @@ M 33 21.99
test = np.genfromtxt(TextIO(data), delimiter=";",
dtype=ndtype, converters=converters)
+ # nested but empty fields also aren't supported
+ ndtype = [('idx', int), ('code', object), ('nest', [])]
+ with assert_raises_regex(NotImplementedError,
+ 'Nested fields.* not supported.*'):
+ test = np.genfromtxt(TextIO(data), delimiter=";",
+ dtype=ndtype, converters=converters)
+
def test_userconverters_with_explicit_dtype(self):
# Test user_converters w/ explicit (standard) dtype
data = TextIO('skip,skip,2001-01-01,1.0,skip')