def show_df(df, ctx, n=3, sort=True): if df and ctx: # and not ctx.cortex_config["hide_data_in_logs"]: col_order = df.columns if sort: col_order = sorted(col_order) samples = [sample.asDict() for sample in df.head(n)] util.print_samples_horiz( samples, sep="", first_sep=":", pad=4, first_pad=2, key_list=col_order )
def test_print_samples_horiz(caplog): caplog.set_level(logging.INFO) samples = [ { "test1": float(120), "test2": 0.2, "testlongstring": 0.20, "a": 0.23, "b": 0.233333333333333333, }, { "test1": 11, "test2": 18, "testreallyreallyreallyreallyreallylongstring": 18, "a": -12, "b": 10, }, { "test1": 13, "test2": 13, "testlongstring": 13, "testreallyreallyreallyreallyreallylongstring": 13, "a": 133333, "b": None, }, ] util.print_samples_horiz(samples) records = [r.message for r in caplog.records] expected = ("a: 0.23, -12, 133333\n" "b: 0.23, 10,\n" "test1: 120.00, 11, 13\n" "test2: 0.20, 18, 13\n" "testlongstring: 0.20, , 13\n" "testreallyreallyr...: , 18, 13\n") assert "\n".join(records) + "\n" == expected