8000 BUG: Correctly identify comma seperated dtype strings · numpy/numpy@b48c804 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit b48c804

Browse files
simongibbonscharris
authored andcommitted
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
1 parent d0ba54f commit b48c804

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

numpy/core/src/multiarray/descriptor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ _check_for_commastring(char *type, Py_ssize_t len)
198198
* allows commas inside of [], for parameterized dtypes to use.
199199
*/
200200
sqbracket = 0;
201-
for (i = 1; i < len; i++) {
201+
for (i = 0; i < len; i++) {
202202
switch (type[i]) {
203203
case ',':
204204
if (sqbracket == 0) {

numpy/core/tests/test_dtype.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,5 +719,10 @@ def test_dtypes_are_true():
719719
assert bool(np.dtype([('a', 'i8'), ('b', 'f4')]))
720720

721721

722+
def test_invalid_dtype_string():
723+
# test for gh-10440
724+
assert_raises(TypeError, np.dtype, 'f8,i8,[f8,i8]')
725+
726+
722727
if __name__ == "__main__":
723728
run_module_suite()

0 commit comments

Comments
 (0)
0