def test_materialize(): DT1 = dt.Frame(A=range(12))[::2, :] DT2 = dt.repeat(dt.Frame(B=["red", "green", "blue"]), 2) DT3 = dt.Frame(C=[4, 2, 9.1, 12, 0]) DT = dt.cbind(DT1, DT2, DT3, force=True) assert frame_columns_virtual(DT) == (True, True, True) DT.materialize() assert frame_columns_virtual(DT) == (False, False, False)
def test_issue1225(): f0 = dt.Frame(A=[1, 2, 3], B=[5, 6, 8], stypes={"B": "int8"}) f1 = f0[::-1, :][:, [dt.float64(f.A), f.B]] assert frame_columns_virtual(f1) == [True, True] f1.materialize() assert f1.stypes == (stype.float64, stype.int8) assert f1.to_list() == [[3.0, 2.0, 1.0], [8, 6, 5]]
def test_cbind_views3(): d0 = dt.Frame(A=range(10))[::-1, :] d1 = dt.Frame(B=list("abcde") * 2) d2 = dt.Frame(C=range(1000))[[14, 19, 35, 17, 3, 0, 1, 0, 10, 777], :] d0.cbind([d1, d2]) assert d0.to_list() == [list(range(10))[::-1], list("abcde" * 2), [14, 19, 35, 17, 3, 0, 1, 0, 10, 777]] assert frame_columns_virtual(d0) == [True, False, True]
def test_dt0_properties(dt0): """Test basic properties of the Frame object.""" assert isinstance(dt0, dt.Frame) assert dt0.nrows == 10 assert dt0.ncols == 3 assert dt0.shape == (10, 3) # must be a tuple, not a list! assert dt0.names == ("colA", "colB", "colC") assert dt0.ltypes == (ltype.bool, ltype.int, ltype.real) assert dt0.stypes == (stype.bool8, stype.int16, stype.float64) assert not any(frame_columns_virtual(dt0)) frame_integrity_check(dt0)
def test_cast_views_all(viewtype, source_stype, target_stype): # TODO: add rowindex with NAs after #1496 # TODO: add rowindex ARR64 somehow... selector = [ slice(1, None, 2), slice(3, -1), [5, 2, 3, 0, 0, 3, 7], dt.Frame([3, 0, 1, 4], stype=dt.int64) ][viewtype] DT = dt.Frame(A=range(10), stype=source_stype) DT = DT[selector, :] assert frame_columns_virtual(DT)[0] assert DT.stypes == (source_stype, ) RES = DT[:, target_stype(f.A)] assert RES.stypes == (target_stype, ) ans1 = RES.to_list()[0] DT.materialize() ans2 = DT[:, target_stype(f.A)].to_list()[0] assert ans1 == ans2
def test_internal_rowindex(): d0 = dt.Frame(list(range(100))) d1 = d0[:20, :] assert frame_columns_virtual(d0) == (False,) assert frame_columns_virtual(d1) == (True,)
def isview(frame): return any(frame_columns_virtual(frame))