def test_append3(): # test append on empty frame f = Frame(num_rows=5) data = {'h': th.ones((3, 2))} f.append(data) assert f.num_rows == 8 ans = th.cat([th.zeros((5, 2)), th.ones((3, 2))], dim=0) assert U.allclose(f['h'].data, ans) # test append with new column data = {'h': 2 * th.ones((3, 2)), 'w': 2 * th.ones((3, 2))} f.append(data) assert f.num_rows == 11 ans1 = th.cat([ans, 2 * th.ones((3, 2))], 0) ans2 = th.cat([th.zeros((8, 2)), 2 * th.ones((3, 2))], 0) assert U.allclose(f['h'].data, ans1) assert U.allclose(f['w'].data, ans2)
def test_append1(): # test append API on Frame data = create_test_data() f1 = Frame() f2 = Frame(data) f1.append(data) assert f1.num_rows == N f1.append(f2) assert f1.num_rows == 2 * N c1 = f1['a1'] assert tuple(F.shape(c1.data)) == (2 * N, D) truth = F.cat([data['a1'], data['a1']], 0) assert F.allclose(truth, c1.data) # append dict of different length columns should fail f3 = {'a1' : F.zeros((3, D)), 'a2' : F.zeros((3, D)), 'a3' : F.zeros((2, D))} def failed_append(): f1.append(f3) assert check_fail(failed_append)
def test_append2(): # test append on FrameRef data = Frame(create_test_data()) f = FrameRef(data) assert f.is_contiguous() assert f.is_span_whole_column() assert f.num_rows == N # append on the underlying frame should not reflect on the ref data.append(data) assert f.is_contiguous() assert not f.is_span_whole_column() assert f.num_rows == N # append on the FrameRef should work f.append(data) assert not f.is_contiguous() assert not f.is_span_whole_column() assert f.num_rows == 3 * N new_idx = list(range(N)) + list(range(2*N, 4*N)) assert F.array_equal(f._index.tousertensor(), F.copy_to(F.tensor(new_idx, dtype=F.int64), F.cpu())) assert data.num_rows == 4 * N
def test_append2(): # test append on FrameRef data = Frame(create_test_data()) f = FrameRef(data) assert f.is_contiguous() assert f.is_span_whole_column() assert f.num_rows == N # append on the underlying frame should not reflect on the ref data.append(data) assert f.is_contiguous() assert not f.is_span_whole_column() assert f.num_rows == N # append on the FrameRef should work f.append(data) assert not f.is_contiguous() assert not f.is_span_whole_column() assert f.num_rows == 3 * N new_idx = list(range(N)) + list(range(2 * N, 4 * N)) assert th.all( f.index().tousertensor() == th.tensor(new_idx, dtype=th.int64)) assert data.num_rows == 4 * N