diff options
author | Simon Gibbons <simongibbons@gmail.com> | 2018-02-18 16:19:38 +0000 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2018-02-18 12:37:55 -0700 |
commit | b48c804fcbe7a177353c462fed02391a2549a20d (patch) | |
tree | 9951ec81da322644b87b5b3181fb3532eefe83b8 | |
parent | d0ba54f958efe07d3a1fc94bf61d3723ef89c267 (diff) | |
download | numpy-b48c804fcbe7a177353c462fed02391a2549a20d.tar.gz |
BUG: Correctly identify comma seperated dtype strings
When parsing dtype strings, we should only consider them to
be comma seperated if there are commas not present in a
pair of square brackets.
Whilst we had a check for this already in the code there was
an off by 1 bug where we failed to consider the first character
of the string. This would lead to an infinite recursion when
trying to parse strings of the form `[i8,f8]`.
Fixes: #10440
-rw-r--r-- | numpy/core/src/multiarray/descriptor.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_dtype.py | 5 |
2 files changed, 6 insertions, 1 deletions
diff --git a/numpy/core/src/multiarray/descriptor.c b/numpy/core/src/multiarray/descriptor.c index 897155238..b4a0ce37d 100644 --- a/numpy/core/src/multiarray/descriptor.c +++ b/numpy/core/src/multiarray/descriptor.c @@ -198,7 +198,7 @@ _check_for_commastring(char *type, Py_ssize_t len) * allows commas inside of [], for parameterized dtypes to use. */ sqbracket = 0; - for (i = 1; i < len; i++) { + for (i = 0; i < len; i++) { switch (type[i]) { case ',': if (sqbracket == 0) { diff --git a/numpy/core/tests/test_dtype.py b/numpy/core/tests/test_dtype.py index 110ae378b..2f997b4f7 100644 --- a/numpy/core/tests/test_dtype.py +++ b/numpy/core/tests/test_dtype.py @@ -719,5 +719,10 @@ def test_dtypes_are_true(): assert bool(np.dtype([('a', 'i8'), ('b', 'f4')])) +def test_invalid_dtype_string(): + # test for gh-10440 + assert_raises(TypeError, np.dtype, 'f8,i8,[f8,i8]') + + if __name__ == "__main__": run_module_suite() |