diff options
author | dhuard <dhuard@localhost> | 2008-04-03 14:17:08 +0000 |
---|---|---|
committer | dhuard <dhuard@localhost> | 2008-04-03 14:17:08 +0000 |
commit | 1b8a670793e06d3450bacc499fad5f074a95c8e7 (patch) | |
tree | b9b8b1047475fec1956c6e8353728f0ca1500b9f /numpy/lib | |
parent | 8784a1abd5c74dbd134a04a4bcd0f050fe650ed6 (diff) | |
download | numpy-1b8a670793e06d3450bacc499fad5f074a95c8e7.tar.gz |
added 1D tests for loadtxt and savetxt. Fixed a bug
Diffstat (limited to 'numpy/lib')
-rw-r--r-- | numpy/lib/io.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test_io.py | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/numpy/lib/io.py b/numpy/lib/io.py index 7be3c9804..7ef7df933 100644 --- a/numpy/lib/io.py +++ b/numpy/lib/io.py @@ -353,7 +353,7 @@ def savetxt(fname, X, fmt='%.18e',delimiter=' '): X = np.asarray(X) origShape = None - if len(X.shape)==1 and not hasattr(X.dtype, 'names'): + if len(X.shape)==1 and X.dtype.names is None: origShape = X.shape X.shape = len(X), 1 for row in X: diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 19dbc8fd6..35203a38d 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -16,6 +16,13 @@ class Testsavetxt(NumpyTestCase): c.seek(0) assert(c.readlines(), ['1 2\n', '3 4\n']) + def test_1D(self): + a = np.array([1,2,3,4], int) + c = StringIO.StringIO() + np.savetxt(c, a, fmt='%d') + c.seek(0) + assert(c.readlines(), ['1\n', '2\n', '3\n', '4\n']) + def test_record(self): a = np.array([(1, 2), (3, 4)], dtype=[('x', '<i4'), ('y', '<i4')]) c = StringIO.StringIO() @@ -48,5 +55,13 @@ class Testloadtxt(NumpyTestCase): a = np.array([[1,2],[3,4]], float) assert_array_equal(x, a) + def test_1D(self): + c = StringIO.StringIO() + c.write('1\n2\n3\n4\n') + c.seek(0) + x = np.loadtxt(c, dtype=int) + a = np.array([1,2,3,4], int) + assert_array_equal(x, a) + if __name__ == "__main__": NumpyTest().run() |