def test_tonumpy_with_NAs2(numpy): src = [[2.3, 11.89, None, math.inf], [4, None, None, -12]] d0 = dt.Frame(src) a0 = d0.to_numpy() assert a0.T.tolist() == src
def test_rename_bad2(): d0 = dt.Frame([[1], [2], ["hello"]], names=("a", "b", "c")) with pytest.raises(KeyError) as e: d0.names = {"xxx": "yyy"} assert "Cannot find column xxx in the Frame" == str(e.value)
def test_rename_bad4(): d0 = dt.Frame([[1], [2], ["hello"]], names=("a", "b", "c")) with pytest.raises(ValueError) as e: d0.names = ('k', ) assert ("The names list has length 1, while the Frame has 3 columns" in str(e.value))
def test_dt_repeat2(): f0 = dt.Frame(["A", "B", "CDE"]) f1 = dt.repeat(f0, 7) frame_integrity_check(f1) assert f1.to_list() == [f0.to_list()[0] * 7]
def test_dt_repeat_empty_frame(): f0 = dt.Frame() f1 = dt.repeat(f0, 5) frame_integrity_check(f1) assert f1.to_list() == []
def test_resize_rows_api(): f0 = dt.Frame([20]) f0.nrows = 3 f0.nrows = 5 frame_integrity_check(f0) assert f0.to_list() == [[20, None, None, None, None]]
def test_resize_invalidates_stats(): f0 = dt.Frame([3, 1, 4, 1, 5, 9, 2, 6]) assert_equals(f0.max(), dt.Frame([9])) f0.nrows = 3 frame_integrity_check(f0) assert_equals(f0.max(), dt.Frame([4]))
def test_len2(): DT = dt.Frame([None, "", "mooo" * 10000], stype="str64") RES = DT[:, f[0].len()] assert RES.stype == dt.stype.int64 assert RES.to_list() == [[None, 0, 40000]]
def test_len_wrong_col(): DT = dt.Frame(range(34)) with pytest.raises(TypeError, match="Function len cannot be applied to " "a column of type int32"): assert DT[:, f[0].len()]
def test_dt_pos(src): DT = dt.Frame(src) RES = DT[:, +f[0]] stype0 = stype.int32 if DT.stype in [dt.bool8, dt.int8, dt.int16] else \ DT.stype assert_equals(RES, dt.Frame(src, stype=stype0))
def test_len(): DT = dt.Frame(A=["", "one", "2", "three", "four", None, "six", "seventy"]) RES = DT[:, f.A.len()] assert RES.stype == dt.stype.int64 assert RES.to_list() == [[0, 3, 1, 5, 4, None, 3, 7]]
def test_tonumpy_with_NAs_view(): # See issue #1738 X = dt.Frame(A=[5.7, 2.3, None, 4.4, 9.8, None])[1:, :] a = X.to_numpy() assert a.tolist() == [[2.3], [None], [4.4], [9.8], [None]]
def test_tonumpy_with_NAs4(numpy): src = [True, False, None] d0 = dt.Frame(src) a0 = d0.to_numpy() assert a0.dtype == numpy.dtype("bool") assert a0.T.tolist() == [src]
def test_tonumpy_with_NAs3(numpy): src = ["faa", None, "", "hooray", None] d0 = dt.Frame(src) a0 = d0.to_numpy() assert a0.T.tolist() == [src]
def test_names_deduplication(): with pytest.warns(dt.exceptions.DatatableWarning): DT = dt.Frame(names=["A", "A01", "A01"]) assert DT.names == ("A", "A01", "A2")
def test_len_unicode(): DT = dt.Frame([ "л╝л░л╣л┤л░лй", "УњЎУњѓтиеУЪњ", "ЪцЦ", "ЮћўЮћФЮћдЮћаЮћгЮћАЮћб" ]) RES = DT[:, f[0].len()] assert_equals(RES, dt.Frame([6, 4, 1, 7], stype=dt.int64))
def test__len__(): DT = dt.Frame(A=[1, 2], B=[3, 7], D=["a", 'n'], V=[1.1, None]) assert len(DT) == 4 assert DT.__len__() == 4 with pytest.raises(TypeError): assert DT.__len__(3)
def test_dt_neg(src): DT = dt.Frame(src) RES = DT[:, -f[0]] stype0 = dt.int32 if DT.stype in [dt.bool8, dt.int8, dt.int16] else \ DT.stype assert_equals(RES, dt.Frame([neg(x) for x in src], stype=stype0))
def test_resize_issue1527(capsys): f0 = dt.Frame(A=[]) assert f0.nrows == 0 f0.nrows = 5 assert f0.nrows == 5 assert f0.to_list() == [[None] * 5]
def test_materialize_to_memory_bad_type(): DT = dt.Frame(range(5)) msg = r"Argument to_memory in Frame.materialize\(\) should be a boolean" with pytest.raises(TypeError, match=msg): DT.materialize(to_memory=0)
def test_dt_repeat(): f0 = dt.Frame(range(10)) f1 = dt.repeat(f0, 3) frame_integrity_check(f1) assert f1.to_list() == [list(range(10)) * 3]
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 test_dt_repeat_view(): f0 = dt.Frame(A=[1, 3, 4, 5], B=[2, 6, 3, 1]) f1 = f0[::2, :] f2 = dt.repeat(f1, 5) frame_integrity_check(f2) assert f2.to_dict() == {"A": [1, 4] * 5, "B": [2, 3] * 5}
def test_issue2269(): import ctypes DT = dt.Frame(range(10000)) ptr = dt.internal.frame_column_data_r(DT, 0) assert isinstance(ptr, ctypes.c_void_p)
def test_rename_bad1(): d0 = dt.Frame([[1], [2], ["hello"]], names=("a", "b", "c")) with pytest.raises(TypeError): d0.names = {"a", "b"}
def test_sizeof(): DT1 = dt.Frame(A=["foo"]) DT2 = dt.Frame(A=["foo" * 1001]) assert sys.getsizeof(DT2) - sys.getsizeof(DT1) == 3000
def test_rename_bad3(): d0 = dt.Frame([[1], [2], ["hello"]], names=("a", "b", "c")) with pytest.raises(ValueError) as e: d0.names = ['1', '2', '3', '5'] assert ("The names list has length 4, while the Frame has only 3 columns" in str(e.value))
def test_dt_getitem3(): DT = dt.Frame([3]) a = DT[0] assert a.to_list() == [[3]] del a # should not emit an error
def test_rename_bad5(): d0 = dt.Frame([[1], [2], ["hello"]], names=("a", "b", "c")) with pytest.raises(TypeError) as e: d0.names = {"a": 17} assert ("The replacement name for column a should be a string, " "but got <class 'int'>" == str(e.value))
def test_tonumpy_with_NAs1(numpy): src = [1, 5, None, 187, None, 103948] d0 = dt.Frame(src) a0 = d0.to_numpy() assert a0.T.tolist() == [src]