Пример #1
0
    def test_describe_cols(self):
        test_list = [[1, 2],[2, 3],[3, 4],[4, 5],[5, 6],[6, 7]]
        test_nd = np.array(test_list)
        test_sa = np.array([(1, 2, 'a'), (2, 3, 'b'), (3, 4, 'c'), (4, 5, 'd'), 
                            (5, 6, 'e'), (6, 7, 'f')], 
                           dtype=[('id', int), ('val', float), ('name', 'S1')])
        ctrl_list = np.array([('f0', 6, 3.5, 1.707825127659933, 1, 6),
                              ('f1', 6, 4.5, 1.707825127659933, 2, 7)],
                             dtype=[('Column Name', 'S2'), ('Count', int),
                                    ('Mean', float), ('Standard Dev', float),
                                    ('Minimum', int), ('Maximum', int)])
        ctrl_printout = """
  Column Name Count Mean  Standard Dev Minimum Maximum
0          f0     6  3.5 1.70782512766       1       6
1          f1     6  4.5 1.70782512766       2       7
        """.strip()
        with uft.rerout_stdout() as get_stdout:
            self.assertTrue(uft.array_equal(ctrl_list, 
                                            describe_cols(
                                                test_list)))
            self.assertEqual(get_stdout().strip(), ctrl_printout)
        self.assertTrue(uft.array_equal(ctrl_list, 
                                        describe_cols(
                                            test_nd, verbose=False)))
        ctrl_sa = np.array([('id', 6, 3.5, 1.707825127659933, 1, 6),
                            ('val', 6, 4.5, 1.707825127659933, 2, 7),
                            ('name', np.nan, np.nan, np.nan, np.nan, np.nan)],
                           dtype=[('Column Name', 'S4'), ('Count', float),
                                  ('Mean', float), ('Standard Dev', float),
                                  ('Minimum', float), ('Maximum', float)])
        self.assertTrue(uft.array_equal(ctrl_sa, 
                                        describe_cols(
                                            test_sa,
                                            verbose=False)))
Пример #2
0
 def test_describe_cols(self):
     test_list = [[1, 2],[2, 3],[3, 4],[4, 5],[5, 6],[6, 7]]
     test_nd = np.array(test_list)
     test_sa = np.array([(1, 2, 'a'), (2, 3, 'b'), (3, 4, 'c'), (4, 5, 'd'), 
                         (5, 6, 'e'), (6, 7, 'f')], 
                        dtype=[('id', int), ('val', float), ('name', 'S1')])
     ctrl_list = np.array([('f0', 6, 3.5, 1.707825127659933, 1, 6),
                           ('f1', 6, 4.5, 1.707825127659933, 2, 7)],
                          dtype=[('Column Name', 'S2'), ('Count', int),
                                 ('Mean', float), ('Standard Dev', float),
                                 ('Minimum', int), ('Maximum', int)])
     self.assertTrue(uft.array_equal(ctrl_list, 
                                     describe_cols(test_list)))
     self.assertTrue(uft.array_equal(ctrl_list, 
                                     describe_cols(test_nd)))
     ctrl_sa = np.array([('id', 6, 3.5, 1.707825127659933, 1, 6),
                         ('val', 6, 4.5, 1.707825127659933, 2, 7),
                         ('name', np.nan, np.nan, np.nan, np.nan, np.nan)],
                        dtype=[('Column Name', 'S4'), ('Count', float),
                               ('Mean', float), ('Standard Dev', float),
                               ('Minimum', float), ('Maximum', float)])
     self.assertTrue(uft.array_equal(ctrl_sa, 
                                     describe_cols(test_sa)))