コード例 #1
0
def test_multi_index_df_to_jinja_table():
    # Create multi-index table
    idx = np.array([['super1', 'super1', 'super1', 'super1', 'super2', 'super2', 'super2'],
                    ['a', 'a', 'b', 'b', 'c', 'c', 'c'],
                    ['aa', 'aa', 'ba', 'bb', 'ca', 'cb', 'cc']])
    idx_tuples = list(zip(*idx))
    multi_index = pd.MultiIndex.from_tuples(idx_tuples, names=['super-level', 'a-level', 'aa-level'])
    columns = ['This is an incredibly long column name', 'column2', 'column3', 'column4', 'column5']
    data = pd.DataFrame(np.random.rand(7, 5) * 2 - 1, index=multi_index, columns=columns)
    fmt_expand_multi_index = tf.FmtExpandMultiIndex(operator=tf.OP_SUM, bold=True,
                                                    hline_color=colors.DARK_BLUE)
    fmt_nDecimal = tf.FmtDecimals(n=2)
    fmt_align_cells = tf.FmtAlignCellContents(alignment='right')
    fmt_heatmap_1 = tf.FmtHeatmap(columns=['column2', 'column3'], rows=['aa', 'ac'], threshold=0., axis=0)
    fmt_heatmap_2 = tf.FmtHeatmap(columns=['column4', 'column5'], rows=['ca', 'cc'], threshold=0.3,
                                  min_color=colors.PURPLE, max_color=colors.ORANGE)
    fmt_stripes_bg = tf.FmtStripeBackground(first_color=colors.LIGHT_GREY)
    fmt_rotate_header = tf.FmtHeader(fixed_width='500px', top_padding='200px')

    formatters = [fmt_expand_multi_index, fmt_align_cells, fmt_stripes_bg, fmt_heatmap_1, fmt_heatmap_2,
                  fmt_rotate_header, fmt_nDecimal]

    # Create table
    table = Block(data, formatters=formatters)
    filename = 'Multi_index_table.pdf'
    table.save(filename)
    # And clean up file afterwards
    os.remove(filename)
コード例 #2
0
def test_FmtHeader_cell_css_selected_column():
    fmt = pbtf.FmtHeader(index_width='10cm', columns=['aa'])
    # We should only get a result for column aa
    data = FormatterData(0., pbtf.HEADER_ROW_NAME, 'aa', df)
    res = fmt._create_cell_level_css(data)
    assert 'white-space:nowrap' in res
    # But nothing for column bb
    data = FormatterData(0., pbtf.HEADER_ROW_NAME, 'bb', df)
    res = fmt._create_cell_level_css(data)
    assert res is None
コード例 #3
0
def test_FmtHeader_cell_css_all_columns():
    fmt = pbtf.FmtHeader(index_width='10cm')
    data = FormatterData(0., pbtf.HEADER_ROW_NAME, 'aa', df)
    res = fmt._create_cell_level_css(data)
    assert 'white-space:nowrap' in res
    assert pbtf.CSS_WIDTH not in res
    data = FormatterData(0., pbtf.HEADER_ROW_NAME, pbtf.INDEX_COL_NAME, df)
    res = fmt._create_cell_level_css(data)
    assert 'white-space:nowrap' in res
    assert pbtf.CSS_WIDTH in res
    data = FormatterData(TEST_STRING, 'a', 'aa', df)
    res = fmt._create_cell_level_css(data)
    assert res is None
コード例 #4
0
ファイル: test_table.py プロジェクト: tobyatgithub/PyBloqs
def test_multi_index_df_to_jinja_table():
    # Create multi-index table
    idx = np.array([['super1', 'super1', 'super1', 'super1', 'super2', 'super2', 'super2'],
                    ['a', 'a', 'b', 'b', 'c', 'c', 'c'],
                    ['aa', 'ab', 'ba', 'bb', 'ca', 'cb', 'cc']])
    idx_tuples = list(zip(*idx))
    multi_index = pd.MultiIndex.from_tuples(idx_tuples, names=['super-level', 'a-level', 'aa-level'])
    columns = ['This is an incredibly long column name', 'column2', 'column3', 'column4', 'column5']
    data = pd.DataFrame(TABLE_DATA, index=multi_index, columns=columns)
    fmt_expand_multi_index = blformat.FmtExpandMultiIndex(operator=blformat.OP_SUM, bold=True,
                                                          hline_color=colors.DARK_BLUE)
    fmt_ndecimal = blformat.FmtDecimals(n=2)
    fmt_align_cells = blformat.FmtAlignCellContents(alignment='right')
    fmt_heatmap_1 = blformat.FmtHeatmap(columns=['column2', 'column3'], rows=['aa', 'ab', 'ac'], threshold=0., axis=0)
    fmt_heatmap_2 = blformat.FmtHeatmap(columns=['column4', 'column5'], rows=['ca', 'cb', 'cc'], threshold=0.3,
                                        min_color=colors.PURPLE, max_color=colors.ORANGE)
    fmt_rotate_header = blformat.FmtHeader(fixed_width='500px', top_padding='200px')

    formatters = [fmt_expand_multi_index, fmt_align_cells,  fmt_heatmap_1, fmt_heatmap_2,
                  fmt_rotate_header, fmt_ndecimal]

    return Block(data, formatters=formatters, use_default_formatters=False)
コード例 #5
0
def test_FmtHeader_table_css():
    fmt = pbtf.FmtHeader()
    res = fmt._create_table_level_css()
    assert 'table-layout:fixed;' in res