diff options
author | Leon Weber <leon@leonweber.de> | 2013-05-23 19:24:28 +0200 |
---|---|---|
committer | Leon Weber <leon@leonweber.de> | 2013-05-29 15:35:45 +0200 |
commit | fc4ade26312bd66474834aa0bee42265e7e15353 (patch) | |
tree | f359efccf95e83fa8f281f3c14bf39d621149b56 /numpy/matrixlib/tests/test_defmatrix.py | |
parent | 8ff5e37bff03925da4c1b121b38188f9fd779b4d (diff) | |
download | numpy-fc4ade26312bd66474834aa0bee42265e7e15353.tar.gz |
ENH: Fix SyntaxError when matrix() is called with invalid string
The numpy.matrix constructor uses eval(str.translate(table)) to convert
input strings to numeric matrix contents. str.translate(table) will
return empty string if str consists only of invalid characters, causing
SyntaxError in eval(). This is confusing, as one would expect an
exception like TypeError when trying to construct a matrix from invalid
input.
This fix makes sure eval() is only called if str is not empty and
TypeError is raised otherwise.
Diffstat (limited to 'numpy/matrixlib/tests/test_defmatrix.py')
-rw-r--r-- | numpy/matrixlib/tests/test_defmatrix.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/numpy/matrixlib/tests/test_defmatrix.py b/numpy/matrixlib/tests/test_defmatrix.py index bc2b747e7..0cf284b64 100644 --- a/numpy/matrixlib/tests/test_defmatrix.py +++ b/numpy/matrixlib/tests/test_defmatrix.py @@ -31,6 +31,10 @@ class TestCtor(TestCase): mvec = matrix(vec) assert_(mvec.shape == (1,5)) + def test_exceptions(self): + # Check for TypeError when called with invalid string data. + assert_raises(TypeError, matrix, "invalid") + def test_bmat_nondefault_str(self): A = array([[1,2],[3,4]]) B = array([[5,6],[7,8]]) |