Пример #1
0
 def test04(self):
     """Testing append() with another ctable"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     ra2 = np.fromiter(((i, i*2.) for i in xrange(N, N+10)), dtype='i4,f8')
     t2 = ca.ctable(ra2)
     t.append(t2)
     ra = np.fromiter(((i, i*2.) for i in xrange(N+10)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
Пример #2
0
 def test04(self):
     """Testing append() with another ctable"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     ra2 = np.fromiter(((i, i * 2.) for i in xrange(N, N + 10)),
                       dtype='i4,f8')
     t2 = ca.ctable(ra2)
     t.append(t2)
     ra = np.fromiter(((i, i * 2.) for i in xrange(N + 10)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
Пример #3
0
 def test02(self):
     """Testing __getitem__ with a short boolean array"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     barr = np.zeros(len(t)-1, dtype=np.bool_)
     self.assertRaises(IndexError, t.__getitem__, barr)
Пример #4
0
def open(rootdir, mode='a'):
    """
    open(rootdir, mode='a')

    Open a disk-based carray/ctable.

    Parameters
    ----------
    rootdir : pathname (string)
        The directory hosting the carray/ctable object.
    mode : the open mode (string)
        Specifies the mode in which the object is opened.  The supported
        values are:

          * 'r' for read-only
          * 'w' for emptying the previous underlying data
          * 'a' for allowing read/write on top of existing data

    Returns
    -------
    out : a carray/ctable object or None (if not objects are found)

    """
    # First try with a carray
    obj = None
    try:
        obj = ca.carray(rootdir=rootdir, mode=mode)
    except IOError:
        # Not a carray.  Now with a ctable
        try:
            obj = ca.ctable(rootdir=rootdir, mode=mode)
        except IOError:
            # Not a ctable
            pass
    return obj
Пример #5
0
 def _test02d(self):
     """Testing where() with an expression (with outcols IV)"""
     N = self.N
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     where = t.where('f1 > f2', outcols='f3,  f0')
     self.assertRaises(ValueError, where.next)
Пример #6
0
 def test00(self):
     """Testing __len__()"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     self.assert_(len(t) == len(ra), "Objects do not have the same length")
Пример #7
0
 def test03(self):
     """Testing __getitem__ with an invalid expression"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     # In t['f1*4 >= ppp'], 'ppp' variable name should be found
     self.assertRaises(NameError, t.__getitem__, 'f1*4 >= ppp')
Пример #8
0
 def test01b(self):
     """Testing cparams when adding a new column (numpy flavor)"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, cparams=ca.cparams(1))
     c = np.arange(N, dtype='i8') * 3
     t.addcol(c, 'f2')
     self.assert_(t['f2'].cparams.clevel == 1, "Incorrect clevel")
Пример #9
0
 def _test02d(self):
     """Testing where() with an expression (with outcols IV)"""
     N = self.N
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     where = t.where('f1 > f2', outcols='f3,  f0')
     self.assertRaises(ValueError, where.next)
Пример #10
0
 def test00(self):
     """Testing append() with scalar values"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     t.append((N, N * 2))
     ra = np.fromiter(((i, i * 2.) for i in xrange(N + 1)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
Пример #11
0
 def test01b(self):
     """Testing cparams when adding a new column (numpy flavor)"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, cparams=ca.cparams(1))
     c = np.arange(N, dtype='i8')*3
     t.addcol(c, 'f2')
     self.assert_(t['f2'].cparams.clevel == 1, "Incorrect clevel")
Пример #12
0
 def test03(self):
     """Testing copy() with no shuffle"""
     N = 10 * 1000
     ra = np.fromiter(((i, i**2.2) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     t2 = t.copy(cparams=ca.cparams(shuffle=False))
     #print "cbytes in f1, f2:", t['f1'].cbytes, t2['f1'].cbytes
     self.assert_(t['f1'].cbytes < t2['f1'].cbytes, "clevel not changed")
Пример #13
0
 def test02(self):
     """Testing __getitem__ with a short boolean array"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     barr = np.zeros(len(t) - 1, dtype=np.bool_)
     self.assertRaises(IndexError, t.__getitem__, barr)
Пример #14
0
 def test02(self):
     """Testing ctable creation from an structured array"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     #print "t->", `t`
     #print "ra[:]", ra[:]
     assert_array_equal(t[:], ra, "ctable values are not correct")
Пример #15
0
 def test00(self):
     """Testing append() with scalar values"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     t.append((N, N*2))
     ra = np.fromiter(((i, i*2.) for i in xrange(N+1)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
Пример #16
0
 def test03(self):
     """Testing __getitem__ with an invalid expression"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     # In t['f1*4 >= ppp'], 'ppp' variable name should be found
     self.assertRaises(NameError, t.__getitem__, 'f1*4 >= ppp')
Пример #17
0
 def test03(self):
     """Testing copy() with no shuffle"""
     N = 10*1000
     ra = np.fromiter(((i, i**2.2) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     t2 = t.copy(cparams=ca.cparams(shuffle=False))
     #print "cbytes in f1, f2:", t['f1'].cbytes, t2['f1'].cbytes
     self.assert_(t['f1'].cbytes < t2['f1'].cbytes, "clevel not changed")
Пример #18
0
 def test02(self):
     """Testing ctable creation from an structured array"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     #print "t->", `t`
     #print "ra[:]", ra[:]
     assert_array_equal(t[:], ra, "ctable values are not correct")
Пример #19
0
 def test00(self):
     """Testing __getitem__ with only a start"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     start = 9
     #print "t->", `t`
     #print "ra[:]", ra[:]
     assert_array_equal(t[start], ra[start], "ctable values are not correct")
Пример #20
0
 def test02(self):
     """Testing __sizeof__() (small ctables)"""
     N = int(111)
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     #print "size t uncompressed ->", t.nbytes
     #print "size t compressed   ->", t.cbytes
     self.assert_(sys.getsizeof(t) > t.nbytes, "ctable compress too much??")
Пример #21
0
 def test01(self):
     """Testing __sizeof__() (big ctables)"""
     N = int(1e4)
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     #print "size t uncompressed ->", t.nbytes
     #print "size t compressed   ->", t.cbytes
     self.assert_(sys.getsizeof(t) < t.nbytes,
                  "ctable does not seem to compress at all")
Пример #22
0
 def test02(self):
     """Testing __sizeof__() (small ctables)"""
     N = int(111)
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     #print "size t uncompressed ->", t.nbytes
     #print "size t compressed   ->", t.cbytes
     self.assert_(sys.getsizeof(t) > t.nbytes,
                  "ctable compress too much??")
Пример #23
0
 def test03(self):
     """Testing where() with an expression (with nrow__ in outcols)"""
     N = self.N
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = [r for r in t.where('4+f1 > f2', outcols=['nrow__','f2','f0'])]
     rl = [(i, i*3, i) for i in xrange(N) if 4+i > i*2]
     #print "rt->", rt, type(rt[0][0])
     #print "rl->", rl, type(rl[0][0])
     self.assert_(rt == rl, "where not working correctly")
Пример #24
0
 def test03(self):
     """Testing __getitem__ with a column name"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     colname = "f1"
     #print "t->", `t[colname]`
     #print "ra->", ra[colname]
     assert_array_equal(t[colname][:], ra[colname],
                        "ctable values are not correct")
Пример #25
0
 def test02(self):
     """Testing copy() with lower clevel"""
     N = 10 * 1000
     ra = np.fromiter(((i, i**2.2) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     t2 = t.copy(cparams=ca.cparams(clevel=1))
     self.assert_(t.cparams.clevel == ca.cparams().clevel)
     self.assert_(t2.cparams.clevel == 1)
     #print "cbytes in f1, f2:", t['f1'].cbytes, t2['f1'].cbytes
     self.assert_(t['f1'].cbytes < t2['f1'].cbytes, "clevel not changed")
Пример #26
0
 def test02(self):
     """Testing append() with carrays"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     a = np.arange(N, N + 10, dtype='i4')
     b = np.arange(N, N + 10, dtype='f8') * 2.
     t.append((ca.carray(a), ca.carray(b)))
     ra = np.fromiter(((i, i * 2.) for i in xrange(N + 10)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
Пример #27
0
 def test02c(self):
     """Testing where() with an expression (with outcols III)"""
     N = self.N
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = [(f2, f0) for f0,f2 in t.where('4+f1 > f2', outcols='f0,f2')]
     rl = [(i*3, i) for i in xrange(N) if 4+i > i*2]
     #print "rt->", rt
     #print "rl->", rl
     self.assert_(rt == rl, "where not working correctly")
Пример #28
0
 def test02(self):
     """Testing append() with carrays"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     a = np.arange(N, N+10, dtype='i4')
     b = np.arange(N, N+10, dtype='f8')*2.
     t.append((ca.carray(a), ca.carray(b)))
     ra = np.fromiter(((i, i*2.) for i in xrange(N+10)), dtype='i4,f8')
     assert_array_equal(t[:], ra, "ctable values are not correct")
Пример #29
0
 def test07(self):
     """Testing ctable.iter() with start, stop, step and limit, skip"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4)
     cl = [r.f1 for r in t.iter(1,9,2, limit=2, skip=1)]
     nl = [r['f1'] for r in ra[1:9:2][1:3]]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
Пример #30
0
 def test01c(self):
     """Testing where() with an expression (mix values)"""
     N = self.N
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = [r.f0 for r in t.where('4+f1 > f2')]
     rl = [i for i in xrange(N) if 4+i > i*2]
     #print "rt->", rt
     #print "rl->", rl
     self.assert_(rt == rl, "where not working correctly")
Пример #31
0
 def test03(self):
     """Testing ctable.iter() with outcols"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4)
     cl = [tuple(r) for r in t.iter(outcols='f2, nrow__, f0')]
     nl = [(r['f2'], i, r['f0']) for i, r in enumerate(ra)]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
Пример #32
0
 def test00(self):
     """Testing __getitem__ with only a start"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     start = 9
     #print "t->", `t`
     #print "ra[:]", ra[:]
     assert_array_equal(t[start], ra[start],
                        "ctable values are not correct")
Пример #33
0
 def test01(self):
     """Testing ctable creation from a tuple of numpy arrays"""
     N = 1e1
     a = np.arange(N, dtype='i4')
     b = np.arange(N, dtype='f8') + 1
     t = ca.ctable((a, b), ('f0', 'f1'))
     #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")
Пример #34
0
 def test04(self):
     """Testing ctable.iter() with start,stop,step and outcols"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4)
     cl = [r for r in t.iter(1,9,3, 'f2, nrow__ f0')]
     nl = [(r['f2'], r['f0'], r['f0']) for r in ra[1:9:3]]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
Пример #35
0
 def test04(self):
     """Testing eval() with a boolean as output"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     ctr = t.eval("f0 >= f1")
     rar = ra['f0'] >= ra['f1']
     #print "ctable ->", ctr
     #print "numpy  ->", rar
     assert_array_equal(ctr[:], rar, "ctable values are not correct")
Пример #36
0
 def test01(self):
     """Testing eval() with columns and constants"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     ctr = t.eval("f0 * f1 * 3")
     rar = ra['f0'] * ra['f1'] * 3
     #print "ctable ->", ctr
     #print "numpy  ->", rar
     assert_array_equal(ctr[:], rar, "ctable values are not correct")
Пример #37
0
 def test03(self):
     """Testing fancy indexing (list of floats)"""
     N = 101
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = t[[2.3, 5.6]]
     rar = ra[[2.3, 5.6]]
     #print "rt->", rt
     #print "rar->", rar
     assert_array_equal(rt, rar, "ctable values are not correct")
Пример #38
0
 def test02(self):
     """Testing copy() with lower clevel"""
     N = 10*1000
     ra = np.fromiter(((i, i**2.2) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     t2 = t.copy(cparams=ca.cparams(clevel=1))
     self.assert_(t.cparams.clevel == ca.cparams().clevel)
     self.assert_(t2.cparams.clevel == 1)
     #print "cbytes in f1, f2:", t['f1'].cbytes, t2['f1'].cbytes
     self.assert_(t['f1'].cbytes < t2['f1'].cbytes, "clevel not changed")
Пример #39
0
 def test01(self):
     """Testing ctable.iter() without params"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4)
     cl = [r.f1 for r in t.iter()]
     nl = [r['f1'] for r in ra]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
Пример #40
0
 def test02(self):
     """Testing __getitem__ with start, stop, step"""
     N = 10
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     start, stop, step = 3, 9, 2
     #print "t->", `t[start:stop:step]`
     #print "ra->", ra[start:stop:step]
     assert_array_equal(t[start:stop:step], ra[start:stop:step],
                        "ctable values are not correct")
Пример #41
0
 def test01(self):
     """Testing ctable creation from a tuple of numpy arrays"""
     N = 1e1
     a = np.arange(N, dtype='i4')
     b = np.arange(N, dtype='f8')+1
     t = ca.ctable((a, b), ('f0', 'f1'))
     #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")
Пример #42
0
 def test02(self):
     """Testing fancy indexing with an empty list"""
     N = 10*1000
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = t[[]]
     rar = ra[[]]
     #print "rt->", rt
     #print "rar->", rar
     assert_array_equal(rt, rar, "ctable values are not correct")
Пример #43
0
 def test04(self):
     """Testing __getitem__ with a list of column names"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     colnames = ["f0", "f2"]
     #print "t->", `t[colnames]`
     #print "ra->", ra[colnames]
     assert_array_equal(t[colnames][:], ra[colnames],
                        "ctable values are not correct")
Пример #44
0
 def test03(self):
     """Testing __getitem__ with a column name"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     colname = "f1"
     #print "t->", `t[colname]`
     #print "ra->", ra[colname]
     assert_array_equal(t[colname][:], ra[colname],
                        "ctable values are not correct")
Пример #45
0
 def test02(self):
     """Testing __getitem__ with start, stop, step"""
     N = 10
     ra = np.fromiter(((i, i*2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra)
     start, stop, step = 3, 9, 2
     #print "t->", `t[start:stop:step]`
     #print "ra->", ra[start:stop:step]
     assert_array_equal(t[start:stop:step], ra[start:stop:step],
                        "ctable values are not correct")
Пример #46
0
 def test02c(self):
     """Testing where() with an expression (with outcols III)"""
     N = self.N
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = [(f2, f0) for f0, f2 in t.where('4+f1 > f2', outcols='f0,f2')]
     rl = [(i * 3, i) for i in xrange(N) if 4 + i > i * 2]
     #print "rt->", rt
     #print "rl->", rl
     self.assert_(rt == rl, "where not working correctly")
Пример #47
0
 def test01(self):
     """Testing __sizeof__() (big ctables)"""
     N = int(1e4)
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     #print "size t uncompressed ->", t.nbytes
     #print "size t compressed   ->", t.cbytes
     self.assert_(
         sys.getsizeof(t) < t.nbytes,
         "ctable does not seem to compress at all")
Пример #48
0
 def test01(self):
     """Testing eval() with columns and constants"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     ctr = t.eval("f0 * f1 * 3")
     rar = ra['f0'] * ra['f1'] * 3
     #print "ctable ->", ctr
     #print "numpy  ->", rar
     assert_array_equal(ctr[:], rar, "ctable values are not correct")
Пример #49
0
 def test02(self):
     """Testing fancy indexing with an empty list"""
     N = 10 * 1000
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = t[[]]
     rar = ra[[]]
     #print "rt->", rt
     #print "rar->", rar
     assert_array_equal(rt, rar, "ctable values are not correct")
Пример #50
0
 def test03(self):
     """Testing fancy indexing (list of floats)"""
     N = 101
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = t[[2.3, 5.6]]
     rar = ra[[2.3, 5.6]]
     #print "rt->", rt
     #print "rar->", rar
     assert_array_equal(rt, rar, "ctable values are not correct")
Пример #51
0
 def test01(self):
     """Testing ctable.iter() without params"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4)
     cl = [r.f1 for r in t.iter()]
     nl = [r['f1'] for r in ra]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
Пример #52
0
 def test07(self):
     """Testing ctable.iter() with start, stop, step and limit, skip"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4)
     cl = [r.f1 for r in t.iter(1, 9, 2, limit=2, skip=1)]
     nl = [r['f1'] for r in ra[1:9:2][1:3]]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
Пример #53
0
 def test02(self):
     """Testing __getitem__ with an expression (true/false values)"""
     N = 10
     ra = np.fromiter(((i, i*2., i*3) for i in xrange(N)), dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = t['f1*4 >= f2*2']
     rar = np.fromiter(((i, i*2., i*3) for i in xrange(N) if i*4 >= i*2.*2),
                       dtype='i4,f8,i8')
     #print "rt->", rt
     #print "rar->", rar
     assert_array_equal(rt, rar, "ctable values are not correct")
Пример #54
0
 def test03(self):
     """Testing where() with an expression (with nrow__ in outcols)"""
     N = self.N
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = [r for r in t.where('4+f1 > f2', outcols=['nrow__', 'f2', 'f0'])]
     rl = [(i, i * 3, i) for i in xrange(N) if 4 + i > i * 2]
     #print "rt->", rt, type(rt[0][0])
     #print "rl->", rl, type(rl[0][0])
     self.assert_(rt == rl, "where not working correctly")
Пример #55
0
 def test04(self):
     """Testing __setitem__ with a large step"""
     N = 100
     ra = np.fromiter(((i, i * 2.) for i in xrange(N)), dtype='i4,f8')
     t = ca.ctable(ra, chunklen=10)
     sl = slice(1, 43, 20)
     t[sl] = (0, 1)
     ra[sl] = (0, 1)
     #print "t[%s] -> %r" % (sl, t)
     #print "ra[%s] -> %r" % (sl, ra)
     assert_array_equal(t[:], ra, "ctable values are not correct")
Пример #56
0
 def test03(self):
     """Testing ctable.iter() with outcols"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4)
     cl = [tuple(r) for r in t.iter(outcols='f2, nrow__, f0')]
     nl = [(r['f2'], i, r['f0']) for i, r in enumerate(ra)]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")
Пример #57
0
 def test01c(self):
     """Testing where() with an expression (mix values)"""
     N = self.N
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     rt = [r.f0 for r in t.where('4+f1 > f2')]
     rl = [i for i in xrange(N) if 4 + i > i * 2]
     #print "rt->", rt
     #print "rl->", rl
     self.assert_(rt == rl, "where not working correctly")
Пример #58
0
 def test04(self):
     """Testing eval() with a boolean as output"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     ctr = t.eval("f0 >= f1")
     rar = ra['f0'] >= ra['f1']
     #print "ctable ->", ctr
     #print "numpy  ->", rar
     assert_array_equal(ctr[:], rar, "ctable values are not correct")
Пример #59
0
 def test04(self):
     """Testing __getitem__ with a list of column names"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra)
     colnames = ["f0", "f2"]
     #print "t->", `t[colnames]`
     #print "ra->", ra[colnames]
     assert_array_equal(t[colnames][:], ra[colnames],
                        "ctable values are not correct")
Пример #60
0
 def test04(self):
     """Testing ctable.iter() with start,stop,step and outcols"""
     N = 10
     ra = np.fromiter(((i, i * 2., i * 3) for i in xrange(N)),
                      dtype='i4,f8,i8')
     t = ca.ctable(ra, chunklen=4)
     cl = [r for r in t.iter(1, 9, 3, 'f2, nrow__ f0')]
     nl = [(r['f2'], r['f0'], r['f0']) for r in ra[1:9:3]]
     #print "cl ->", cl
     #print "nl ->", nl
     self.assert_(cl == nl, "iter not working correctily")