Source code orco/ext/pandas.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pandas as pd


def export_builder(runtime, builder_name, missing=pd.NA, arg_prefix="arg."):
    """
    Export builder into pandas  DataFrame
    """

    cols = {"comp_time": []}
    for i, job in enumerate(runtime.db.export_builder(builder_name)):
        cols["comp_time"].append(job.computation_time)
        for k, v in job.config.items():
            n = arg_prefix + k
            if n not in cols:
                cols[n] = [missing] * i
            c = cols[n]
            if len(c) != i:
                c.extend([missing] * (i - len(c)))
            c.append(v)
    return pd.DataFrame(cols)


def unpack_frame(frame, unpack_column="config"):
    new = pd.DataFrame(list(frame[unpack_column]))
    new = pd.concat([frame, new], axis=1)
    new.drop(unpack_column, inplace=True, axis=1)
    return new