summaryrefslogtreecommitdiff
path: root/numpy/lib/tests
diff options
context:
space:
mode:
authorPaul Anton Letnes <paul.anton.letnes@gmail.com>2011-11-27 14:35:59 +0100
committerRalf Gommers <ralf.gommers@googlemail.com>2011-12-28 17:35:26 +0100
commit1475319160baed782daa39e0de0c0655c2abe4b5 (patch)
treecd2d52893de80bfe0e75e2e15a697dc16478a726 /numpy/lib/tests
parent166d0819dc86fb68380b66ffa91c966fa77cbc26 (diff)
downloadnumpy-1475319160baed782daa39e0de0c0655c2abe4b5.tar.gz
BUG: savetxt now handles complex arrays. Closes #1573.
Diffstat (limited to 'numpy/lib/tests')
-rw-r--r--numpy/lib/tests/test_io.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py
index 54c2ddabb..356534a25 100644
--- a/numpy/lib/tests/test_io.py
+++ b/numpy/lib/tests/test_io.py
@@ -273,6 +273,39 @@ class TestSaveTxt(TestCase):
finally:
os.unlink(name)
+ def test_complex_arrays(self):
+ ncols = 2
+ nrows = 2
+ a = np.zeros((ncols, nrows), dtype=np.complex128)
+ re = np.pi
+ im = np.e
+ a[:] = re + 1.0j * im
+ # One format only
+ c = StringIO()
+ np.savetxt(c, a, fmt=' %+.3e')
+ c.seek(0)
+ lines = c.readlines()
+ assert_equal(lines, asbytes_nested([
+ ' ( +3.142e+00+ +2.718e+00j) ( +3.142e+00+ +2.718e+00j)\n',
+ ' ( +3.142e+00+ +2.718e+00j) ( +3.142e+00+ +2.718e+00j)\n']))
+ # One format for each real and imaginary part
+ c = StringIO()
+ np.savetxt(c, a, fmt=' %+.3e' * 2 * ncols)
+ c.seek(0)
+ lines = c.readlines()
+ assert_equal(lines, asbytes_nested([
+ ' +3.142e+00 +2.718e+00 +3.142e+00 +2.718e+00\n',
+ ' +3.142e+00 +2.718e+00 +3.142e+00 +2.718e+00\n']))
+ # One format for each complex number
+ c = StringIO()
+ np.savetxt(c, a, fmt=['(%.3e%+.3ej)'] * ncols)
+ c.seek(0)
+ lines = c.readlines()
+ assert_equal(lines, asbytes_nested([
+ '(3.142e+00+2.718e+00j) (3.142e+00+2.718e+00j)\n',
+ '(3.142e+00+2.718e+00j) (3.142e+00+2.718e+00j)\n']))
+
+
class TestLoadTxt(TestCase):
def test_record(self):