def test_cast_list_of_list_to_sa1(self): test = [[1,2.,'a'],[2,4.,'b'],[4,5.,'g']] names = ['ints','floats','strings'] correct_1 = np.array([(1, 2.0, 'a'), (2, 4.0, 'b'), (4, 5.0, 'g')],dtype=[('f0', '<i8'), ('f1', '<f8'), ('f2', 'S1')]) correct_2 = np.array([(1, 2.0, 'a'), (2, 4.0, 'b'), (4, 5.0, 'g')], dtype=[('ints', '<i8'), ('floats', '<f8'), ('strings', 'S1')]) self.assertTrue(np.array_equal(correct_1, utils.cast_list_of_list_to_sa(test))) self.assertTrue(np.array_equal(correct_2, utils.cast_list_of_list_to_sa(test, names)))
def test_cast_list_of_list_to_sa2(self): L = [[None, None, None], ['a', 5, None], ['ab', 'x', None]] ctrl = np.array( [('', '', ''), ('a', '5', ''), ('ab', 'x', '')], dtype=[('f0', 'S2'), ('f1', 'S1'), ('f2', 'S1')]) conv = utils.cast_list_of_list_to_sa(L) self.assertTrue(np.array_equal(conv, ctrl)) L = [[None, u'\u05dd\u05d5\u05dc\u05e9', 4.0, 7], [2, 'hello', np.nan, None], [4, None, None, 14L]] ctrl = np.array( [(-999, u'\u05dd\u05d5\u05dc\u05e9', 4.0, 7), (2, u'hello', np.nan, -999L), (4, u'', np.nan, 14L)], dtype=[('int', int), ('ucode', 'U5'), ('float', float), ('long', long)]) conv = utils.cast_list_of_list_to_sa( L, col_names=['int', 'ucode', 'float', 'long']) self.assertTrue(uft.array_equal(ctrl, conv))
def test_col_fewer_than_n_nonzero(self): M = cast_list_of_list_to_sa( [[0,2,3], [0,3,4], [1,4,5]], col_names=['height','weight', 'age']) arguments = [{'func': col_fewer_than_n_nonzero, 'vals': 2}] M = remove_cols_where(M, arguments) correct = cast_list_of_list_to_sa( [[2,3], [3,4], [4,5]], col_names=['weight', 'age']) self.assertTrue(np.array_equal(M, correct))
def test_col_val_eq_any(self): M = cast_list_of_list_to_sa( [[1,2,3], [1,3,4], [1,4,5]], col_names=['height','weight', 'age']) arguments = [{'func': col_val_eq_any, 'vals': None}] M = remove_cols_where(M, arguments) correct = cast_list_of_list_to_sa( [[2,3], [3,4], [4,5]], col_names=['weight', 'age']) self.assertTrue(np.array_equal(M, correct))
def add_legend(self): """ Adds a legend that shows which trial number in a summary graph corresponds to which Trial """ if self.__exp is None: raise ReportError('No experiment provided for this report. ' 'Cannot add legend.') list_of_tuple = [(str(i), str(trial)) for i, trial in enumerate(self.__exp.trials)] table = cast_list_of_list_to_sa(list_of_tuple, col_names=('Id', 'Trial')) # display 10 at a time to give pdfkit an easier time with page breaks start_row = 0 n_trials = len(list_of_tuple) while start_row < n_trials: self.add_table(table[start_row:start_row+9]) start_row += 9
def add_legend(self): """ Adds a legend that shows which trial number in a summary graph corresponds to which Trial """ if self.__exp is None: raise ReportError('No experiment provided for this report. ' 'Cannot add legend.') list_of_tuple = [(str(i), str(trial)) for i, trial in enumerate(self.__exp.trials)] table = cast_list_of_list_to_sa(list_of_tuple, col_names=('Id', 'Trial')) # display 10 at a time to give pdfkit an easier time with page breaks start_row = 0 n_trials = len(list_of_tuple) while start_row < n_trials: self.add_table(table[start_row:start_row + 9]) start_row += 9
def test_remove_rows_where(self): M = [[1,2,3], [2,3,4], [3,4,5]] col_names = ['heigh','weight', 'age'] lables= [0,0,1] M = diogenes.utils.cast_list_of_list_to_sa( M, col_names=col_names) arguments = [{'func': row_val_eq, 'col_name': 'heigh', 'vals': 1}, {'func': row_val_lt, 'col_name': 'weight', 'vals': 3}, {'func': row_val_between, 'col_name': 'age', 'vals': (3, 4)}] res = remove_rows_where( M, arguments) ctrl = cast_list_of_list_to_sa([[2,3,4],[3,4,5]],col_names=['heigh','weight', 'age']) self.assertTrue(np.array_equal(res, ctrl))