# [Numpy-svn] r6122 - trunk/numpy/lib/tests

numpy-svn@scip... numpy-svn@scip...
Sat Nov 29 06:09:20 CST 2008

```Author: stefan
Date: 2008-11-29 06:09:07 -0600 (Sat, 29 Nov 2008)
New Revision: 6122

Modified:
trunk/numpy/lib/tests/test_io.py
Log:
Reformat spacing in io tests.

Modified: trunk/numpy/lib/tests/test_io.py
===================================================================
--- trunk/numpy/lib/tests/test_io.py	2008-11-29 12:08:29 UTC (rev 6121)
+++ trunk/numpy/lib/tests/test_io.py	2008-11-29 12:09:07 UTC (rev 6122)
@@ -49,10 +49,10 @@
a = np.array([[1, 2], [3, 4]], int)
self.roundtrip(a)

-        a = np.array([[1+5j, 2+6j], [3+7j, 4+8j]], dtype=np.csingle)
+        a = np.array([[1 + 5j, 2 + 6j], [3 + 7j, 4 + 8j]], dtype=np.csingle)
self.roundtrip(a)

-        a = np.array([[1+5j, 2+6j], [3+7j, 4+8j]], dtype=np.cdouble)
+        a = np.array([[1 + 5j, 2 + 6j], [3 + 7j, 4 + 8j]], dtype=np.cdouble)
self.roundtrip(a)

def test_1D(self):
@@ -79,13 +79,13 @@

def test_multiple_arrays(self):
-        a = np.array( [[1,2],[3,4]], float)
-        b = np.array( [[1+2j,2+7j],[3-6j,4+12j]], complex)
+        a = np.array([[1, 2], [3, 4]], float)
+        b = np.array([[1 + 2j, 2 + 7j], [3 - 6j, 4 + 12j]], complex)
self.roundtrip(a,b)

def test_named_arrays(self):
-        a = np.array( [[1,2],[3,4]], float)
-        b = np.array( [[1+2j,2+7j],[3-6j,4+12j]], complex)
+        a = np.array([[1, 2], [3, 4]], float)
+        b = np.array([[1 + 2j, 2 + 7j], [3 - 6j, 4 + 12j]], complex)
c = StringIO.StringIO()
np.savez(c, file_a=a, file_b=b)
c.seek(0)
@@ -96,7 +96,7 @@

class TestSaveTxt(TestCase):
def test_array(self):
-        a =np.array( [[1,2],[3,4]], float)
+        a =np.array([[1, 2], [3, 4]], float)
c = StringIO.StringIO()
np.savetxt(c, a)
c.seek(0)
@@ -104,14 +104,14 @@
['1.000000000000000000e+00 2.000000000000000000e+00\n',
'3.000000000000000000e+00 4.000000000000000000e+00\n'])

-        a =np.array( [[1,2],[3,4]], int)
+        a =np.array([[1, 2], [3, 4]], int)
c = StringIO.StringIO()
np.savetxt(c, a, fmt='%d')
c.seek(0)

def test_1D(self):
-        a = np.array([1,2,3,4], int)
+        a = np.array([1, 2, 3, 4], int)
c = StringIO.StringIO()
np.savetxt(c, a, fmt='%d')
c.seek(0)
@@ -181,12 +181,12 @@

c.seek(0)
-        a = np.array([[1,2],[3,4]], int)
+        a = np.array([[1, 2], [3, 4]], int)
assert_array_equal(x, a)

c.seek(0)
-        a = np.array([[1,2],[3,4]], float)
+        a = np.array([[1, 2], [3, 4]], float)
assert_array_equal(x, a)

def test_1D(self):
@@ -194,14 +194,14 @@
c.write('1\n2\n3\n4\n')
c.seek(0)
-        a = np.array([1,2,3,4], int)
+        a = np.array([1, 2, 3, 4], int)
assert_array_equal(x, a)

c = StringIO.StringIO()
c.write('1,2,3,4\n')
c.seek(0)
-        a = np.array([1,2,3,4], int)
+        a = np.array([1, 2, 3, 4], int)
assert_array_equal(x, a)

def test_missing(self):
@@ -210,7 +210,7 @@
c.seek(0)
x = np.loadtxt(c, dtype=int, delimiter=',', \
converters={3:lambda s: int(s or -999)})
-        a = np.array([1,2,3,-999,5], int)
+        a = np.array([1, 2, 3, -999, 5], int)
assert_array_equal(x, a)

def test_converters_with_usecols(self):
@@ -219,8 +219,8 @@
c.seek(0)
x = np.loadtxt(c, dtype=int, delimiter=',', \
converters={3:lambda s: int(s or -999)}, \
-            usecols=(1, 3, ))
-        a = np.array([[2,  -999],[7, 9]], int)
+            usecols=(1, 3,))
+        a = np.array([[2, -999], [7, 9]], int)
assert_array_equal(x, a)

@@ -229,7 +229,7 @@
c.seek(0)
x = np.loadtxt(c, dtype=int, delimiter=',', \
-        a = np.array([1,2,3,5], int)
+        a = np.array([1, 2, 3, 5], int)
assert_array_equal(x, a)

def test_skiprows(self):
@@ -238,7 +238,7 @@
c.seek(0)
x = np.loadtxt(c, dtype=int, delimiter=',', \
skiprows=1)
-        a = np.array([1,2,3,5], int)
+        a = np.array([1, 2, 3, 5], int)
assert_array_equal(x, a)

c = StringIO.StringIO()
@@ -246,28 +246,28 @@
c.seek(0)
x = np.loadtxt(c, dtype=int, delimiter=',', \
skiprows=1)
-        a = np.array([1,2,3,5], int)
+        a = np.array([1, 2, 3, 5], int)
assert_array_equal(x, a)

def test_usecols(self):
-        a =np.array( [[1,2],[3,4]], float)
+        a = np.array([[1, 2], [3, 4]], float)
c = StringIO.StringIO()
np.savetxt(c, a)
c.seek(0)
assert_array_equal(x, a[:,1])

-        a =np.array( [[1,2,3],[3,4,5]], float)
+        a =np.array([[1, 2, 3], [3, 4, 5]], float)
c = StringIO.StringIO()
np.savetxt(c, a)
c.seek(0)
-        x = np.loadtxt(c, dtype=float, usecols=(1,2))
-        assert_array_equal(x, a[:,1:])
+        x = np.loadtxt(c, dtype=float, usecols=(1, 2))
+        assert_array_equal(x, a[:, 1:])

# Testing with arrays instead of tuples.
c.seek(0)
-        x = np.loadtxt(c, dtype=float, usecols=np.array([1,2]))
-        assert_array_equal(x, a[:,1:])
+        x = np.loadtxt(c, dtype=float, usecols=np.array([1, 2]))
+        assert_array_equal(x, a[:, 1:])

# Checking with dtypes defined converters.
data = '''JOE 70.1 25.3
@@ -276,9 +276,9 @@
c = StringIO.StringIO(data)
names = ['stid', 'temp']
dtypes = ['S4', 'f8']
-        assert_equal(arr['stid'],  ["JOE",  "BOB"])
-        assert_equal(arr['temp'],  [25.3,  27.9])
+        arr = np.loadtxt(c, usecols=(0, 2), dtype=zip(names, dtypes))
+        assert_equal(arr['stid'], ["JOE",  "BOB"])
+        assert_equal(arr['temp'], [25.3,  27.9])

def test_fancy_dtype(self):
c = StringIO.StringIO()
@@ -286,7 +286,7 @@
c.seek(0)
dt = np.dtype([('x', int), ('y', [('t', int), ('s', float)])])
-        a = np.array([(1,(2,3.0)),(4,(5,6.0))], dt)
+        a = np.array([(1, (2, 3.0)), (4, (5, 6.0))], dt)
assert_array_equal(x, a)

def test_empty_file(self):
@@ -297,11 +297,13 @@
c = StringIO.StringIO()
c.writelines(['1 21\n', '3 42\n'])
c.seek(0)
-        data = np.loadtxt(c, usecols=(1,), converters={0: lambda s: int(s, 16)})
+                          converters={0: lambda s: int(s, 16)})
assert_array_equal(data, [21, 42])

c.seek(0)
-        data = np.loadtxt(c, usecols=(1,), converters={1: lambda s: int(s, 16)})
+                          converters={1: lambda s: int(s, 16)})
assert_array_equal(data, [33, 66])

class Testfromregex(TestCase):
@@ -312,7 +314,8 @@

dt = [('num', np.float64), ('val', 'S3')]
x = np.fromregex(c, r"([0-9.]+)\s+(...)", dt)
-        a = np.array([(1.312, 'foo'), (1.534, 'bar'), (4.444, 'qux')], dtype=dt)
+        a = np.array([(1.312, 'foo'), (1.534, 'bar'), (4.444, 'qux')],
+                     dtype=dt)
assert_array_equal(x, a)

def test_record_2(self):
@@ -323,7 +326,8 @@

dt = [('num', np.int32), ('val', 'S3')]
x = np.fromregex(c, r"(\d+)\s+(...)", dt)
-        a = np.array([(1312, 'foo'), (1534, 'bar'), (4444, 'qux')], dtype=dt)
+        a = np.array([(1312, 'foo'), (1534, 'bar'), (4444, 'qux')],
+                     dtype=dt)
assert_array_equal(x, a)

def test_record_3(self):

```