Commit 7406a300 authored by Pierre Augier's avatar Pierre Augier
Browse files

Fix bug str2type("uint32")

parent 0f8d2e2d70c2
......@@ -39,8 +39,9 @@ def test_NDim():
def test_str2type_simple():
str2type("int") ==
str2type("float") == np.float
assert str2type("int") ==
assert str2type("float") == np.float
assert str2type("uint32") == np.uint32
def test_str2type_arrays():
......@@ -48,8 +49,8 @@ def test_str2type_arrays():
compare_array_types(str2type("int[]"), A1)
compare_array_types(str2type("int[:]"), A1)
A2 = Array[int, "2d"]
compare_array_types(str2type("int[:,:]"), A2)
A2 = Array[np.uint32, "2d"]
compare_array_types(str2type("uint32[:,:]"), A2)
def test_str2type_or():
......@@ -711,10 +711,20 @@ def str2type(str_type):
return eval(str_type)
except (TypeError, SyntaxError):
except (TypeError, SyntaxError, NameError):
# not a simple type
# could be a numpy type
if not str_type.startswith("np."):
dtype = "np." + str_type
dtype = str_type
return eval(dtype, {"np": np})
except (TypeError, SyntaxError, AttributeError):
if str_type.startswith("(") and str_type.endswith(")"):
re_comma = re.compile(r",(?![^\[]*\])(?![^\(]*\))")
return Tuple[
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment