예제 #1
0
    def test_attr(self):
        """ Set/Get attributes.
        """
        for key, val in self.commdbs.iteritems():
            dbpath = os.path.join(self.tempdir, self.DBTYPE,
                                  'test_attr_%s.db' % key)
            dba = DBArray.fromndarray(val, dbpath, self.DBTYPE)
            data_mean = val.mean(0)
            int_attr = np.random.randint(100)
            flt_attr = np.random.rand()
            str_attr = 'hello world'

            dba['data_mean'] = data_mean
            dba['int_attr'] = int_attr
            dba['str_attr'] = str_attr
            # float is not support currently
            self.assertRaises(TypeError, dba.__setitem__,
                              ('flt_attr', flt_attr))

            self._arr_eq(dba['data_mean'], data_mean)
            self.assertEqual(dba['int_attr'], int_attr)
            self.assertEqual(dba['str_attr'], str_attr)

            del dba
            dba = DBArray(dbpath, self.DBTYPE)

            self._arr_eq(dba['data_mean'], data_mean)
            self.assertEqual(dba['int_attr'], int_attr)
            self.assertEqual(dba['str_attr'], str_attr)
예제 #2
0
    def test_get_data(self):
        for key, val in self.commdbs.iteritems():
            dbpath = os.path.join(self.tempdir, self.DBTYPE,
                                  'test_get_data_%s.db' % key)
            dba = DBArray.fromndarray(val, dbpath, self.DBTYPE)
            self._arr_eq(dba[10], val[10])
            self._arr_eq(dba[10, :], val[10, :])
            self._arr_eq(dba[1:10], val[1:10])
            self._arr_eq(dba[1:10, :], val[1:10, :])

            self._arr_eq(dba[[1, 2, 5]], val[[1, 2, 5]])
예제 #3
0
    def test_from_and_to(self):
        for key, val in self.commdbs.iteritems():
            dbpath = os.path.join(self.tempdir, self.DBTYPE,
                                  'test_from_%s.db' % key)
            dba = DBArray.fromndarray(val, dbpath, self.DBTYPE)
            self._info_eq(dba, val)

            arr = dba.tondarray()
            self._arr_eq(arr, val)

            # cloase and re-open
            del dba
            dba = DBArray(dbpath, self.DBTYPE)
            self._info_eq(dba, val)

            arr = dba.tondarray()
            self._arr_eq(arr, val)