Example #1
0
def test_pivot_median():

    print()
    print('test pivot median')

    df = gen_df()

    # time

    try:
        msg = 'cython'
        tick = time.perf_counter()
        pivot_cython = pivot.pivot_table(df, index=NAME_IDX, columns=NAME_COL, values=NAME_VALUE, fill_value=0.0, aggfunc='median')
        ctime = time.perf_counter() - tick
    except:
        ctime = None

    try:
        msg = 'pandas'
        tick = time.perf_counter()
        pivot_pandas = df.pivot_table(index=NAME_IDX, columns=[NAME_COL], values=NAME_VALUE, fill_value=0.0, aggfunc='median')
        ptime = time.perf_counter() - tick
    except:
        ptime = None

    stime = None

    return ctime, ptime, stime
Example #2
0
def test_multiple_index():

    print()
    print('test pivot sum with multiple index')

    df = gen_df_multiple_index()

    try:
        msg = 'cython'
        tick = time.perf_counter()
        pivot_cython = pivot.pivot_table(df, index=[NAME_IDX, NAME_IDX2], columns=NAME_COL, values=NAME_VALUE, fill_value=0.0, aggfunc='sum')
        ctime = time.perf_counter() - tick
    except:
        ctime = None

    try:
        msg = 'pandas'
        tick = time.perf_counter()
        pivot_pandas = df.pivot_table(index=[NAME_IDX, NAME_IDX2], columns=NAME_COL, values=NAME_VALUE, fill_value=0.0, aggfunc='sum')
        ptime = time.perf_counter() - tick
    except:
        ptime = None
    
    try:
        msg = 'sparse'
        tick = time.perf_counter()
        pivot_sparse_df = pivot_sparse(df, index=[NAME_IDX, NAME_IDX2], columns=NAME_COL, values=NAME_VALUE, fill_value=0.0)
        stime = time.perf_counter() - tick
    except:
        stime = None

    return ctime, ptime, stime
Example #3
0
def test_pivot_nunique_int():
    #TODO: better test (with actual nunique not equal to counts, and longer vectors per (i, j) pair)

    print()
    print('test pivot nunique int')

    df = gen_df_int()

    # time

    try:
        msg = 'cython'
        tick = time.perf_counter()
        pivot_cython = pivot.pivot_table(df, index=NAME_IDX, columns=NAME_COL, values=NAME_VALUE, fill_value=0, aggfunc='nunique')
        ctime = time.perf_counter() - tick
    except:
        ctime = None

    try:
        msg = 'pandas'
        tick = time.perf_counter()
        pivot_pandas = df.pivot_table(index=NAME_IDX, columns=[NAME_COL], values=NAME_VALUE, fill_value=0, aggfunc='nunique')
        ptime = time.perf_counter() - tick
    except:
        ptime = None

    stime = None

    return ctime, ptime, stime