summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/lib/io.py2
-rw-r--r--numpy/lib/tests/test_io.py15
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()