diff options
author | Warren Weckesser <warren.weckesser@gmail.com> | 2013-10-20 10:56:27 -0400 |
---|---|---|
committer | Warren Weckesser <warren.weckesser@gmail.com> | 2013-10-20 10:56:27 -0400 |
commit | 0d284764a855cae11699228ff1b81e6d18f38ed2 (patch) | |
tree | 8985294e0e6ac7d93a1167e7367702f88f2cf21e | |
parent | 55d3ef5b81b709cc9d8ad6b13f75ca0f05f65276 (diff) | |
download | numpy-0d284764a855cae11699228ff1b81e6d18f38ed2.tar.gz |
MAINT: io: handle a bad fmt argument in savetxt by raising a ValueError.
-rw-r--r-- | numpy/lib/npyio.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 4 |
2 files changed, 6 insertions, 0 deletions
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py index 9e6989c77..dced7fd78 100644 --- a/numpy/lib/npyio.py +++ b/numpy/lib/npyio.py @@ -1047,6 +1047,8 @@ def savetxt(fname, X, fmt='%.18e', delimiter=' ', newline='\n', header='', raise error else: format = fmt + else: + raise ValueError('invalid fmt: %r' % (fmt,)) if len(header) > 0: header = header.replace('\n', '\n' + comments) diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 9a119e79a..66310a509 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -327,6 +327,10 @@ class TestSaveTxt(TestCase): lines = c.readlines() assert_equal(lines, [b'01 : 2.0\n', b'03 : 4.0\n']) + # Bad fmt, should raise a ValueError + c = BytesIO() + assert_raises(ValueError, np.savetxt, c, a, fmt=99) + def test_header_footer(self): """ Test the functionality of the header and footer keyword argument. |