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") == np.int
str2type("float") == np.float
assert str2type("int") == np.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):
try:
return eval(str_type)
except (TypeError, SyntaxError):
except (TypeError, SyntaxError, NameError):
# not a simple type
pass
# could be a numpy type
try:
if not str_type.startswith("np."):
dtype = "np." + str_type
else:
dtype = str_type
return eval(dtype, {"np": np})
except (TypeError, SyntaxError, AttributeError):
pass
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