Example #1
0
def test_column_multi_index_df_to_jinja_table():
    # Create column multi-index table
    df = pd.DataFrame(np.arange(12, dtype=float).reshape(3, 4), index=['a', 'b', 'c'], columns=['aa', 'bb', 'cc', 'aa'])
    df['grouping'] = 'g'
    df = df.reset_index()
    df = df.groupby(['grouping', 'index']).sum().unstack()
    # Create formatters
    row_css = ['text-align:center', 'text-align:right']
    index_col_css = ['background-color: #00FFFF'] * 2
    fmt_mi_header = tf.FmtColumnMultiIndexRows(row_css=row_css, index_col_css=index_col_css)
    # Create table
    table = Block(df, formatters=[fmt_mi_header])
    filename = 'Column_multi_index_table.pdf'
    table.save(filename)
    # And clean up file afterwards
    os.remove(filename)
Example #2
0
def test_FmtColumnMultiIndexRows():
    df = _create_column_multiindex_df()

    row_css = ['CSS1', 'CSS2']
    index_col_css = ['a', 'b']
    fmt_mi_header = pbtf.FmtColumnMultiIndexRows(row_css=row_css, index_col_css=index_col_css)

    data = FormatterData(None, pbtf.HEADER_ROW_NAME, pbtf.INDEX_COL_NAME, df)
    result = fmt_mi_header._create_cell_level_css(data)
    assert result == 'a'
    data = FormatterData(None, pbtf.HEADER_ROW_NAME, None, df)
    for _ in range(4):
        result = fmt_mi_header._create_cell_level_css(data)
        assert result == 'CSS1'
    data = FormatterData(None, pbtf.HEADER_ROW_NAME, pbtf.INDEX_COL_NAME, df)
    result = fmt_mi_header._create_cell_level_css(data)
    assert result == 'b'
    for _ in range(12):
        result = fmt_mi_header._create_cell_level_css(data)
        assert result == 'CSS2'