Exemplo n.º 1
0
def assert_frame_sort_equal(a, b, **kwargs):
    """Tests that DataFrames are equal, even if rows are in different order"""
    df_a = ungroup(a)
    df_b = ungroup(b)
    sorted_a = robust_multiple_sort(df_a, list(df_a.columns)).reset_index(drop = True)
    sorted_b = robust_multiple_sort(df_b, list(df_b.columns)).reset_index(drop = True)

    assert_frame_equal(sorted_a, sorted_b, **kwargs)
Exemplo n.º 2
0
def assert_frame_sort_equal(a, b):
    """Tests that DataFrames are equal, even if rows are in different order"""
    df_a = ungroup(a)
    df_b = ungroup(b)
    sorted_a = df_a.sort_values(by = df_a.columns.tolist()).reset_index(drop = True)
    sorted_b = df_b.sort_values(by = df_b.columns.tolist()).reset_index(drop = True)

    assert_frame_equal(sorted_a, sorted_b)
Exemplo n.º 3
0
def assert_equal_query(tbl, lazy_query, target, **kwargs):
    out = collect(lazy_query(tbl))

    if isinstance(tbl, pd.DataFrame):
        df_a = ungroup(out).reset_index(drop=True)
        df_b = ungroup(target).reset_index(drop=True)
        assert_frame_equal(df_a, df_b, **kwargs)
    else:
        assert_frame_sort_equal(out, target, **kwargs)
Exemplo n.º 4
0
def test_dply_grouped_mutate_of_agg_order():
    # see issue #139
    df = pd.DataFrame({
        'g': ['b', 'a', 'b'],
        'x':[0, 1, 2]
        })
    gdf = df.groupby('g')
    
    out = mutate(gdf, g_min = lambda d: d.x.min())

    assert_frame_equal(ungroup(out), df.assign(g_min = [0, 1, 0]))