[Numpy-svn] r5323 - trunk/numpy/core/tests

numpy-svn@scip... numpy-svn@scip...
Sat Jun 28 22:26:02 CDT 2008


Author: charris
Date: 2008-06-28 22:26:00 -0500 (Sat, 28 Jun 2008)
New Revision: 5323

Modified:
   trunk/numpy/core/tests/test_records.py
Log:
Add test for ticket #390.


Modified: trunk/numpy/core/tests/test_records.py
===================================================================
--- trunk/numpy/core/tests/test_records.py	2008-06-29 02:28:43 UTC (rev 5322)
+++ trunk/numpy/core/tests/test_records.py	2008-06-29 03:26:00 UTC (rev 5323)
@@ -1,70 +1,72 @@
+import numpy as np
+from numpy.testing import *
 from os import path
-from numpy.testing import *
 set_package_path()
-import numpy.core
-reload(numpy.core)
-import numpy
-from numpy.core import *
 restore_path()
 
 class TestFromrecords(TestCase):
     def test_fromrecords(self):
-        r = rec.fromrecords([[456,'dbe',1.2],[2,'de',1.3]],
+        r = np.rec.fromrecords([[456,'dbe',1.2],[2,'de',1.3]],
                             names='col1,col2,col3')
-        assert_equal(r[0].item(),(456, 'dbe', 1.2))
+        assert_equal(r[0].item(), (456, 'dbe', 1.2))
 
     def test_method_array(self):
-        r = rec.array('abcdefg'*100,formats='i2,a3,i4',shape=3,byteorder='big')
-        assert_equal(r[1].item(),(25444, 'efg', 1633837924))
+        r = np.rec.array('abcdefg'*100,formats='i2,a3,i4',shape=3,byteorder='big')
+        assert_equal(r[1].item(), (25444, 'efg', 1633837924))
 
     def test_method_array2(self):
-        r=rec.array([(1,11,'a'),(2,22,'b'),(3,33,'c'),(4,44,'d'),(5,55,'ex'),
+        r = np.rec.array([(1,11,'a'),(2,22,'b'),(3,33,'c'),(4,44,'d'),(5,55,'ex'),
                      (6,66,'f'),(7,77,'g')],formats='u1,f4,a1')
-        assert_equal(r[1].item(),(2, 22.0, 'b'))
+        assert_equal(r[1].item(), (2, 22.0, 'b'))
 
     def test_recarray_slices(self):
-        r=rec.array([(1,11,'a'),(2,22,'b'),(3,33,'c'),(4,44,'d'),(5,55,'ex'),
+        r = np.rec.array([(1,11,'a'),(2,22,'b'),(3,33,'c'),(4,44,'d'),(5,55,'ex'),
                      (6,66,'f'),(7,77,'g')],formats='u1,f4,a1')
-        assert_equal(r[1::2][1].item(),(4, 44.0, 'd'))
+        assert_equal(r[1::2][1].item(), (4, 44.0, 'd'))
 
     def test_recarray_fromarrays(self):
-        x1 = array([1,2,3,4])
-        x2 = array(['a','dd','xyz','12'])
-        x3 = array([1.1,2,3,4])
-        r = rec.fromarrays([x1,x2,x3],names='a,b,c')
-        assert_equal(r[1].item(),(2,'dd',2.0))
+        x1 = np.array([1,2,3,4])
+        x2 = np.array(['a','dd','xyz','12'])
+        x3 = np.array([1.1,2,3,4])
+        r = np.rec.fromarrays([x1,x2,x3],names='a,b,c')
+        assert_equal(r[1].item(), (2,'dd',2.0))
         x1[1] = 34
-        assert_equal(r.a,array([1,2,3,4]))
+        assert_equal(r.a, np.array([1,2,3,4]))
 
     def test_recarray_fromfile(self):
         data_dir = path.join(path.dirname(__file__),'data')
         filename = path.join(data_dir,'recarray_from_file.fits')
         fd = open(filename)
         fd.seek(2880*2)
-        r = rec.fromfile(fd, formats='f8,i4,a5', shape=3, byteorder='big')
+        r = np.rec.fromfile(fd, formats='f8,i4,a5', shape=3, byteorder='big')
 
     def test_recarray_from_obj(self):
         count = 10
-        a = zeros(count, dtype='O')
-        b = zeros(count, dtype='f8')
-        c = zeros(count, dtype='f8')
+        a = np.zeros(count, dtype='O')
+        b = np.zeros(count, dtype='f8')
+        c = np.zeros(count, dtype='f8')
         for i in range(len(a)):
             a[i] = range(1,10)
 
-        mine = numpy.rec.fromarrays([a,b,c],
-                                    names='date,data1,data2')
+        mine = np.rec.fromarrays([a,b,c], names='date,data1,data2')
         for i in range(len(a)):
-            assert(mine.date[i]==range(1,10))
-            assert(mine.data1[i]==0.0)
-            assert(mine.data2[i]==0.0)
+            assert (mine.date[i] == range(1,10))
+            assert (mine.data1[i] == 0.0)
+            assert (mine.data2[i] == 0.0)
 
+    def check_recarray_from_repr(self):
+        x = np.rec.array([ (1, 2)],dtype=[('a', np.int8), ('b', np.int8)])
+        y = eval("np." + repr(x))
+        assert isinstance(y, np.recarray)
+        assert_equal(y, x)
+        
     def test_recarray_from_names(self):
-        ra = rec.array([
+        ra = np.rec.array([
             (1, 'abc', 3.7000002861022949, 0),
             (2, 'xy', 6.6999998092651367, 1),
             (0, ' ', 0.40000000596046448, 0)],
                        names='c1, c2, c3, c4')
-        pa = rec.fromrecords([
+        pa = np.rec.fromrecords([
             (1, 'abc', 3.7000002861022949, 0),
             (2, 'xy', 6.6999998092651367, 1),
             (0, ' ', 0.40000000596046448, 0)],
@@ -75,7 +77,7 @@
             assert ra[k].item() == pa[k].item()
 
     def test_recarray_conflict_fields(self):
-        ra = rec.array([(1,'abc',2.3),(2,'xyz',4.2),
+        ra = np.rec.array([(1,'abc',2.3),(2,'xyz',4.2),
                         (3,'wrs',1.3)],
                        names='field, shape, mean')
         ra.mean = [1.1,2.2,3.3]
@@ -91,7 +93,7 @@
 
 class TestRecord(TestCase):
     def setUp(self):
-        self.data = rec.fromrecords([(1,2,3),(4,5,6)],
+        self.data = np.rec.fromrecords([(1,2,3),(4,5,6)],
                             dtype=[("col1", "<i4"),
                                    ("col2", "<i4"),
                                    ("col3", "<i4")])



More information about the Numpy-svn mailing list