Exemplo n.º 1
0
    def test_vector_table(self):
        t = Tabulator()
        box = Box(get_lst4())
        values = 'd'
        index = 'c'
        index_vals = [1, 2]
        df = t.vector_table(box, values, index, index_vals)
        expected = '''a     1           2      
b     1     2     1     2
c                        
1  12.0  13.0  16.0  19.0
2  30.0  31.0  34.0  37.0'''
        self.assertEqual(expected, str(df))
Exemplo n.º 2
0
    def test_vector_table_cols_default_index_uneven(self):
        t = Tabulator()
        box = Box(get_lst4_uneven())
        values = 'd'
        index = 'c'
        index_vals = None
        df = t.vector_table(box, values, index, index_vals, orient='cols')
        expected = '''c       1     2     3
a b                  
1 1  12.0  30.0   NaN
  2  13.0  31.0  20.0
2 1  16.0  34.0   NaN
  2  19.0  37.0   NaN'''
        self.assertEqual(expected, str(df))
Exemplo n.º 3
0
    def test_vector_table_cols(self):
        t = Tabulator()
        box = Box(get_lst4())
        values = 'd'
        index = 'c'
        index_vals = [1, 2]
        df = t.vector_table(box, values, index, index_vals, orient='cols')
        expected = '''c       1     2
a b            
1 1  12.0  30.0
  2  13.0  31.0
2 1  16.0  34.0
  2  19.0  37.0'''
        self.assertEqual(expected, str(df))
Exemplo n.º 4
0
    def test_vector_table_arr_single_entry_interpolated_2D(self):
        """ The index is n-by-1, and must be squeezed """
        t = Tabulator()
        box = Box(get_lst7())
        values = 'd'
        index = 'c'
        components = ['x', 'y', 'z']
        df = t.vector_table(box, values, index, components=components)
        expected = '''a     1          
b     1          
d:    x    y    z
c                
1   1.0  3.0  5.0
2   2.0  4.0  6.0'''
        self.assertEqual(expected, str(df))
Exemplo n.º 5
0
    def test_vector_table_arr_single_entry_interpolated(self):
        t = Tabulator()
        box = Box(get_lst6())
        values = 'd'
        index = 'c'
        index_vals = [1, 2]
        components = ['x', 'y', 'z']
        df = t.vector_table(box, values, index, components=components)
        expected = '''a     1          
b     1          
d:    x    y    z
c                
1   1.0  3.0  5.0
2   2.0  4.0  6.0'''
        self.assertEqual(expected, str(df))
Exemplo n.º 6
0
    def test_vector_table_arr(self):
        t = Tabulator()
        box = Box(get_lst5())
        values = 'd'
        index = 'c'
        index_vals = [1, 2]
        components = ['x', 'y', 'z']
        df = t.vector_table(box,
                            values,
                            index,
                            index_vals,
                            components=components)
        expected = '''a     1                           
b     1              2            
d:    x    y    z    x     y     z
c                                 
1   1.0  3.0  5.0  7.0   9.0  11.0
2   2.0  4.0  6.0  8.0  10.0  12.0'''
        self.assertEqual(expected, str(df))
Exemplo n.º 7
0
    def test_to_csv_multiindex_cols(self):
        t = Tabulator()
        box = Box(get_lst4())
        values = 'd'
        index = 'c'
        index_vals = [1, 2]
        df = t.vector_table(box, values, index, index_vals)
        with tempfile.TemporaryDirectory() as tmpdirname:
            fname = os.path.join(tmpdirname, 'test.csv')
            to_csv(df, fname)
            with open(fname, 'r') as f:
                s = f.read()

        expected = '''a,1,1,2,2
b,1,2,1,2
c,,,,
1,12.0,13.0,16.0,19.0
2,30.0,31.0,34.0,37.0
'''
        self.assertEqual(s, expected)