Esempio n. 1
0
    def test00c(self):
        """Testing ctable opening in "a" mode"""
        N = 1e1
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8')+1)
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
        # Open t
        t = ca.open(rootdir=self.rootdir, mode='a')
        #print "t->", `t`

        # Check values
        ra = np.rec.fromarrays([a[:],b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")

        # Now check some accesses
        t.append((10, 11.0))
        t.append((10, 11.0))
        t[-1] = (11, 12.0)

        # Check values
        N = 12
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8')+1)
        ra = np.rec.fromarrays([a[:],b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")
Esempio n. 2
0
    def test00c(self):
        """Testing ctable opening in "a" mode"""
        N = 1e1
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8') + 1)
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
        # Open t
        t = ca.open(rootdir=self.rootdir, mode='a')
        #print "t->", `t`

        # Check values
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")

        # Now check some accesses
        t.append((10, 11.0))
        t.append((10, 11.0))
        t[-1] = (11, 12.0)

        # Check values
        N = 12
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8') + 1)
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")
Esempio n. 3
0
 def test03b(self):
     """Testing `fill` constructor (array default)"""
     a = np.ones((2,2), dtype='(4,)i4')*3
     b = ca.fill((2,2), [3,3,3,3], dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 4
0
 def test00a(self):
     """Testing `carray` reshape"""
     a = np.arange(16).reshape((2,2,4))
     b = ca.arange(16, rootdir=self.rootdir).reshape((2,2,4))
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 5
0
 def test02(self):
     """Testing `ones` constructor"""
     a = np.ones((2,2), dtype='(4,)i4')
     b = ca.ones((2,2), dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 6
0
 def test01b(self):
     """Testing `zeros` constructor (II)"""
     a = np.zeros(2, dtype='(2,4)i4')
     b = ca.zeros(2, dtype='(2,4)i4', rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 7
0
 def test03b(self):
     """Testing `fill` constructor (array default)"""
     a = np.ones((2, 2), dtype='(4,)i4') * 3
     b = ca.fill((2, 2), [3, 3, 3, 3], dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 8
0
 def test02(self):
     """Testing `ones` constructor"""
     a = np.ones((2, 2), dtype='(4,)i4')
     b = ca.ones((2, 2), dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 9
0
 def test00a(self):
     """Testing `carray` reshape"""
     a = np.arange(16).reshape((2, 2, 4))
     b = ca.arange(16, rootdir=self.rootdir).reshape((2, 2, 4))
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 10
0
 def test00b(self):
     """Testing `carray` reshape (large shape)"""
     a = np.arange(16000).reshape((20, 20, 40))
     b = ca.arange(16000, rootdir=self.rootdir).reshape((20, 20, 40))
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 11
0
 def test00b(self):
     """Testing `carray` reshape (large shape)"""
     a = np.arange(16000).reshape((20,20,40))
     b = ca.arange(16000, rootdir=self.rootdir).reshape((20,20,40))
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 12
0
 def test01b(self):
     """Testing `zeros` constructor (II)"""
     a = np.zeros(2, dtype='(2,4)i4')
     b = ca.zeros(2, dtype='(2,4)i4', rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     #print "b->", `b`
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 13
0
 def test00b(self):
     """Testing `__getitem()__` method with only a start (slice)"""
     a = np.ones((27,2700), dtype="i4")*3
     b = ca.fill((27,2700), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = slice(1)
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 14
0
    def testImplicitDtype(self):
        """Testing carray construction keeping dimensions (implicit dtype)"""
        a = np.eye(6) # 2d
        b = ca.carray(a, rootdir=self.rootdir)
        if self.open:
            b = ca.open(rootdir=self.rootdir)

        # array equality implies having the same shape 
        assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 15
0
 def test00b(self):
     """Testing `__getitem()__` method with only a start (slice)"""
     a = np.ones((27, 2700), dtype="i4") * 3
     b = ca.fill((27, 2700), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = slice(1)
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 16
0
    def testImplicitDtype(self):
        """Testing carray construction keeping dimensions (implicit dtype)"""
        a = np.eye(6)  # 2d
        b = ca.carray(a, rootdir=self.rootdir)
        if self.open:
            b = ca.open(rootdir=self.rootdir)

        # array equality implies having the same shape
        assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 17
0
    def testExplicitDtype(self):
        """Testing carray construction keeping dimensions (explicit dtype)"""
        dtype = np.dtype(np.float64)
        a = np.eye(6, dtype=dtype)
        b = ca.carray(a, dtype=dtype, rootdir=self.rootdir)
        if self.open:
            b = ca.open(rootdir=self.rootdir)

        # array equality implies having the same shape
        assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 18
0
 def test00a(self):
     """Testing `__getitem()__` method with only a start (scalar)"""
     a = np.ones((2, 3), dtype="i4") * 3
     b = ca.fill((2, 3), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = 1
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 19
0
 def test04c(self):
     """Testing `__getitem()__` method with shape reduction (III)"""
     a = np.arange(6000).reshape((50,40,3))
     b = ca.carray(a, rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = (1,slice(1,4,2),2)
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 20
0
 def test02(self):
     """Testing `__getitem()__` method with a start, stop, step"""
     a = np.ones((10, 2), dtype="i4") * 3
     b = ca.fill((10, 2), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = slice(1, 9, 2)
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 21
0
 def test04c(self):
     """Testing `__getitem()__` method with shape reduction (III)"""
     a = np.arange(6000).reshape((50, 40, 3))
     b = ca.carray(a, rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = (1, slice(1, 4, 2), 2)
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 22
0
 def test00a(self):
     """Testing `__getitem()__` method with only a start (scalar)"""
     a = np.ones((2,3), dtype="i4")*3
     b = ca.fill((2,3), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = 1
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 23
0
 def test04(self):
     """Testing `fill` constructor with open and resize (array default)"""
     a = np.ones((3,200), dtype='(4,)i4')*3
     b = ca.fill((2,200), [3,3,3,3], dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     c = np.ones((1,200), dtype='(4,)i4')*3
     b.append(c)
     #print "b->", `b`, len(b), b[1]
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 24
0
    def testExplicitDtype(self):
        """Testing carray construction keeping dimensions (explicit dtype)"""
        dtype = np.dtype(np.float64)
        a = np.eye(6, dtype=dtype)
        b = ca.carray(a, dtype=dtype, rootdir=self.rootdir)
        if self.open:
            b = ca.open(rootdir=self.rootdir)

        # array equality implies having the same shape 
        assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 25
0
 def test02(self):
     """Testing `__getitem()__` method with a start, stop, step"""
     a = np.ones((10,2), dtype="i4")*3
     b = ca.fill((10,2), 3, dtype="i4", rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = slice(1,9,2)
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 26
0
 def test03c(self):
     """Testing `__getitem()__` method with several slices (III)"""
     a = np.arange(120*1000).reshape((5*1000,4,3,2))
     b = ca.carray(a, rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = (slice(None,None,3), slice(1,3,2), slice(1,4,2))
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 27
0
 def test03c(self):
     """Testing `__getitem()__` method with several slices (III)"""
     a = np.arange(120 * 1000).reshape((5 * 1000, 4, 3, 2))
     b = ca.carray(a, rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     sl = (slice(None, None, 3), slice(1, 3, 2), slice(1, 4, 2))
     #print "b[sl]->", `b[sl]`
     self.assert_(a[sl].shape == b[sl].shape, "Shape is not equal")
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 28
0
 def test02b(self):
     """Testing `__setitem()__` method with start,stop,step (scalar)"""
     a = np.ones((10, 2), dtype="i4") * 3
     b = ca.fill((10, 2), 3, dtype="i4", rootdir=self.rootdir)
     sl = slice(1, 8, 3)
     a[sl, :] = range(2)
     b[sl] = range(2)
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`, `b`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 29
0
 def test00b(self):
     """Testing `__setitem()__` method with only a start (vector)"""
     a = np.ones((200,300), dtype="i4")*3
     b = ca.fill((200,300), 3, dtype="i4", rootdir=self.rootdir)
     sl = slice(1)
     a[sl,:] = range(300)
     b[sl] = range(300)
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 30
0
 def test04(self):
     """Testing `fill` constructor with open and resize (array default)"""
     a = np.ones((3, 200), dtype='(4,)i4') * 3
     b = ca.fill((2, 200), [3, 3, 3, 3],
                 dtype='(4,)i4',
                 rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     c = np.ones((1, 200), dtype='(4,)i4') * 3
     b.append(c)
     #print "b->", `b`, len(b), b[1]
     assert_array_equal(a, b, "Arrays are not equal")
Esempio n. 31
0
 def test02b(self):
     """Testing `__setitem()__` method with start,stop,step (scalar)"""
     a = np.ones((10,2), dtype="i4")*3
     b = ca.fill((10,2), 3, dtype="i4", rootdir=self.rootdir)
     sl = slice(1,8,3)
     a[sl,:] = range(2)
     b[sl] = range(2)
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`, `b`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 32
0
 def test05(self):
     """Testing `fill` constructor with open and resize (nchunks>1)"""
     a = np.ones((3,2000), dtype='(4,)i4')*3
     b = ca.fill((2,2000), [3,3,3,3], dtype='(4,)i4', rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     c = np.ones((1,2000), dtype='(4,)i4')*3
     b.append(c)
     #print "b->", `b`
     # We need to use the b[:] here to overcome a problem with the
     # assert_array_equal() function
     assert_array_equal(a, b[:], "Arrays are not equal")
Esempio n. 33
0
 def test00b(self):
     """Testing `__setitem()__` method with only a start (vector)"""
     a = np.ones((200, 300), dtype="i4") * 3
     b = ca.fill((200, 300), 3, dtype="i4", rootdir=self.rootdir)
     sl = slice(1)
     a[sl, :] = range(300)
     b[sl] = range(300)
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 34
0
 def test03d(self):
     """Testing `__setitem()__` method with several slices (IV)"""
     a = np.arange(120).reshape((5,4,3,2))
     b = ca.carray(a, rootdir=self.rootdir)
     sl = (slice(1,3), slice(1,3,1), slice(1,None,2), slice(1))
     #print "before->", `b[sl]`
     a[sl] = 2
     b[sl] = 2
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "after->", `b[sl]`
     assert_array_equal(a[:], b[:], "Arrays are not equal")
Esempio n. 35
0
 def test04c(self):
     """Testing `__setitem()__` method with shape reduction (III)"""
     a = np.arange(24).reshape((4, 3, 2))
     b = ca.carray(a, rootdir=self.rootdir)
     sl = (1, 2, slice(None, None, None))
     #print "before->", `b[sl]`
     a[sl] = 2
     b[sl] = 2
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "after->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 36
0
 def test03d(self):
     """Testing `__setitem()__` method with several slices (IV)"""
     a = np.arange(120).reshape((5, 4, 3, 2))
     b = ca.carray(a, rootdir=self.rootdir)
     sl = (slice(1, 3), slice(1, 3, 1), slice(1, None, 2), slice(1))
     #print "before->", `b[sl]`
     a[sl] = 2
     b[sl] = 2
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "after->", `b[sl]`
     assert_array_equal(a[:], b[:], "Arrays are not equal")
Esempio n. 37
0
 def test04c(self):
     """Testing `__setitem()__` method with shape reduction (III)"""
     a = np.arange(24).reshape((4,3,2))
     b = ca.carray(a, rootdir=self.rootdir)
     sl = (1,2,slice(None,None,None))
     #print "before->", `b[sl]`
     a[sl] = 2
     b[sl] = 2
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "after->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 38
0
 def test01a(self):
     """Testing `__setitem()__` method with start,stop (scalar)"""
     a = np.ones((500,200), dtype="i4")*3
     b = ca.fill((500,200), 3, dtype="i4", rootdir=self.rootdir,
                 cparams=ca.cparams())
     sl = slice(100,400)
     a[sl,:] = 0
     b[sl] = 0
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 39
0
 def test05(self):
     """Testing `fill` constructor with open and resize (nchunks>1)"""
     a = np.ones((3, 2000), dtype='(4,)i4') * 3
     b = ca.fill((2, 2000), [3, 3, 3, 3],
                 dtype='(4,)i4',
                 rootdir=self.rootdir)
     if self.open:
         b = ca.open(rootdir=self.rootdir)
     c = np.ones((1, 2000), dtype='(4,)i4') * 3
     b.append(c)
     #print "b->", `b`
     # We need to use the b[:] here to overcome a problem with the
     # assert_array_equal() function
     assert_array_equal(a, b[:], "Arrays are not equal")
Esempio n. 40
0
    def test00b(self):
        """Accessing attributes in a opened carray."""

        cn = self.getobject()
        # Some attrs
        cn.attrs['attr1'] = 'val1'
        cn.attrs['attr2'] = 'val2'
        cn.attrs['attr3'] = 'val3'
        # Re-open the carray
        if self.rootdir:
            cn = ca.open(rootdir=self.rootdir)
        self.assert_(cn.attrs['attr1'] == 'val1')
        self.assert_(cn.attrs['attr2'] == 'val2')
        self.assert_(cn.attrs['attr3'] == 'val3')
        self.assert_(len(cn.attrs) == 3)
Esempio n. 41
0
    def test00a(self):
        """Testing ctable opening in "r" mode"""
        N = 1e1
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8') + 1)
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
        # Open t
        t = ca.open(rootdir=self.rootdir, mode='r')
        #print "t->", `t`
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")

        # Now check some accesses
        self.assertRaises(RuntimeError, t.__setitem__, 1, (0, 0.0))
        self.assertRaises(RuntimeError, t.append, (0, 0.0))
Esempio n. 42
0
    def test00a(self):
        """Testing ctable opening in "r" mode"""
        N = 1e1
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8')+1)
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
        # Open t
        t = ca.open(rootdir=self.rootdir, mode='r')
        #print "t->", `t`
        ra = np.rec.fromarrays([a[:],b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")

        # Now check some accesses
        self.assertRaises(RuntimeError, t.__setitem__, 1, (0, 0.0))
        self.assertRaises(RuntimeError, t.append, (0, 0.0))
Esempio n. 43
0
 def test01c(self):
     """Appending attributes in a opened carray."""
     
     cn = self.getobject()
     # Some attrs
     cn.attrs['attr1'] = 'val1'
     # Reopen
     if self.rootdir:
         cn = ca.open(rootdir=self.rootdir)
     # Append attrs
     cn.attrs['attr2'] = 'val2'
     cn.attrs['attr3'] = 'val3'
     self.assert_(cn.attrs['attr1'] == 'val1')
     self.assert_(cn.attrs['attr2'] == 'val2')
     self.assert_(cn.attrs['attr3'] == 'val3')
     self.assert_(len(cn.attrs) == 3)
Esempio n. 44
0
 def test01a(self):
     """Testing `__setitem()__` method with start,stop (scalar)"""
     a = np.ones((500, 200), dtype="i4") * 3
     b = ca.fill((500, 200),
                 3,
                 dtype="i4",
                 rootdir=self.rootdir,
                 cparams=ca.cparams())
     sl = slice(100, 400)
     a[sl, :] = 0
     b[sl] = 0
     if self.open:
         b.flush()
         b = ca.open(rootdir=self.rootdir)
     #print "b[sl]->", `b[sl]`
     assert_array_equal(a[sl], b[sl], "Arrays are not equal")
Esempio n. 45
0
    def test01b(self):
        """Removing attributes in a opened carray."""

        cn = self.getobject()
        # Some attrs
        cn.attrs['attr1'] = 'val1'
        cn.attrs['attr2'] = 'val2'
        cn.attrs['attr3'] = 'val3'
        # Reopen
        if self.rootdir:
            cn = ca.open(rootdir=self.rootdir)
        # Remove one of them
        del cn.attrs['attr2']
        self.assert_(cn.attrs['attr1'] == 'val1')
        self.assert_(cn.attrs['attr3'] == 'val3')
        self.assertRaises(KeyError, cn.attrs.__getitem__, 'attr2')
        self.assert_(len(cn.attrs) == 2)
Esempio n. 46
0
    def test00b(self):
        """Testing ctable opening in "w" mode"""
        N = 1e1
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8')+1)
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
        # Open t
        t = ca.open(rootdir=self.rootdir, mode='w')
        #print "t->", `t`
        N = 0
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8')+1)
        ra = np.rec.fromarrays([a[:],b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")

        # Now check some accesses
        t.append((0, 0.0))
        t.append((0, 0.0))
        t[1] = (1, 2.0)
        ra = np.rec.fromarrays([(0,1),(0.0, 2.0)], 'i4,f8').view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")
Esempio n. 47
0
    def test00b(self):
        """Testing ctable opening in "w" mode"""
        N = 1e1
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8') + 1)
        t = ca.ctable((a, b), ('f0', 'f1'), rootdir=self.rootdir)
        # Open t
        t = ca.open(rootdir=self.rootdir, mode='w')
        #print "t->", `t`
        N = 0
        a = ca.carray(np.arange(N, dtype='i4'))
        b = ca.carray(np.arange(N, dtype='f8') + 1)
        ra = np.rec.fromarrays([a[:], b[:]]).view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")

        # Now check some accesses
        t.append((0, 0.0))
        t.append((0, 0.0))
        t[1] = (1, 2.0)
        ra = np.rec.fromarrays([(0, 1), (0.0, 2.0)], 'i4,f8').view(np.ndarray)
        #print "ra[:]", ra[:]
        assert_array_equal(t[:], ra, "ctable values are not correct")