def test_all_null(): out = bind_cols(dict(a=NULL, b=NULL)) expect = tibble() assert out.equals(expect) out = bind_cols(NULL) expect = tibble() assert out.equals(expect)
def test_repair_names(): df = tibble(a=1, b=2) bound = bind_cols(df, df) assert bound.columns.tolist() == ["a__0", "b__1", "a__2", "b__3"] t1 = tibble(a=1) t2 = tibble(a=2) bound = bind_cols(t1, t2) assert bound.columns.tolist() == ["a__0", "a__1"]
def test_handle_dict(): expect = tibble(x=1, y="a", z=2) d1 = dict(x=1, y="a") d2 = dict(z=2) out = bind_cols(d1, d2) assert out.equals(expect) out = bind_cols(dict(**d1, **d2)) assert out.equals(expect)
def test_bind_col_null(): df1 = tibble(a=range(1, 11), b=range(1, 11)) df2 = tibble(c=range(1, 11), d=range(1, 11)) res1 = df1 >> bind_cols(df2) res2 = NULL >> bind_cols(df1, df2) res3 = df1 >> bind_cols(NULL, df2) res4 = df1 >> bind_cols(df2, NULL) assert res1.equals(res2) assert res1.equals(res3) assert res1.equals(res4)
def test_bind_empty_dfs(): out = bind_rows(None) assert dim(out) == (0, 0) out = bind_cols(None) assert dim(out) == (0, 0) df1 = tibble(x=factor([1, 2, 3])) df2 = tibble() out = df1 >> bind_rows(df2) assert out.x.tolist() == [1, 2, 3]
def test_incompatible_size_fill_with_NA(): df1 = tibble(x=range(1, 4)) df2 = tibble(y=range(1, 2)) out = (df1 >> bind_cols(df2)).fillna(100) assert out.x.tolist() == [1, 2, 3] assert out.y.tolist() == [1, 100, 100]
def test_empty(): out = bind_cols(tibble()) expect = tibble() assert out.equals(expect)