コード例 #1
0
ファイル: test_utils.py プロジェクト: Deerluluolivia/eights
 def test_cast_list_of_list_to_sa(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(utils_for_tests.array_equal(ctrl, conv))
コード例 #2
0
 def test_remove_row(self):
     M = cast_list_of_list_to_sa([[0, 2, 3], [0, 3, 4], [1, 4, 5]],
                                 col_names=['height', 'weight', 'age'])
     arguments = [{'func': fewer_then_n_nonzero_in_col, 'vals': 2}]
     M = remove_rows_where(M, val_eq, 'weight', 3)
     correct = cast_list_of_list_to_sa(
         [[0, 2, 3], [1, 4, 5]], col_names=['height', 'weight', 'age'])
     self.assertTrue(np.array_equal(M, correct))
コード例 #3
0
 def test_all_same_value(self):
     M = cast_list_of_list_to_sa([[1, 2, 3], [1, 3, 4], [1, 4, 5]],
                                 col_names=['height', 'weight', 'age'])
     arguments = [{'func': all_same_value, 'vals': None}]
     M = remove_col_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))
コード例 #4
0
 def test_remove_row(self):
     M = cast_list_of_list_to_sa(
         [[0,2,3], [0,3,4], [1,4,5]],
         col_names=['height','weight', 'age'])
     arguments = [{'func': fewer_then_n_nonzero_in_col,  'vals': 2}]  
     M = remove_rows_where(M, val_eq, 'weight', 3)
     correct = cast_list_of_list_to_sa(
          [[0, 2, 3], [1, 4, 5]],
         col_names=['height','weight', 'age'])   
     self.assertTrue(np.array_equal(M, correct))   
コード例 #5
0
 def test_all_same_value(self):
     M = cast_list_of_list_to_sa(
         [[1,2,3], [1,3,4], [1,4,5]],
         col_names=['height','weight', 'age'])
     arguments = [{'func': all_same_value,  'vals': None}]  
     M = remove_col_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)) 
コード例 #6
0
 def test_cast_list_of_list_to_sa(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(utils_for_tests.array_equal(ctrl, conv))