def test_issue1406(dt0): with pytest.raises(ValueError) as e: noop(dt0[tuple()]) assert "Single-item selector `DT[a]` is not supported" in str(e.value) with pytest.raises(ValueError) as e: noop(dt0[(None, )]) assert "Single-item selector `DT[a]` is not supported" in str(e.value)
def test_option_bad(): with pytest.raises(AttributeError): noop(dt.options.gooo) with pytest.raises(TypeError) as e: dt.options.register_option(name="gooo", xtype=str, default=3, doc="??") assert "Default value 3 is not of type <class 'str'>" in str(e.value) with pytest.raises(ValueError) as e: dt.options.register_option(name=".hidden", xtype=int, default=0) assert "Invalid option name .hidden" in str(e.value) dt.options.register_option(name="gooo", xtype=int, default=3) with pytest.raises(ValueError) as e: dt.options.register_option(name="gooo", xtype=int, default=4, doc="???") assert "Option gooo already registered" in str(e.value) with pytest.raises(TypeError) as e: dt.options.gooo = 2.5 assert ("Invalid value for option gooo: expected <class 'int'>, instead " "got <class 'float'>" in str(e.value))
def test_cast_object_to_numeric(source_stype, target_stype): DT = dt.Frame(W=[0, 1, 2], stype=source_stype) assert DT.stypes == (source_stype,) with pytest.raises(NotImplementedError) as e: noop(DT[:, target_stype(f.W)]) assert ("Unable to cast %s into %s" % (source_stype.name, target_stype.name) in str(e.value))
def test_ftrl_construct_wrong_combination(): with pytest.raises(TypeError) as e: noop(Ftrl(params=tparams, alpha = tparams.alpha)) assert ("You can either pass all the parameters with `params` or any of " "the individual parameters with `alpha`, `beta`, `lambda1`, " "`lambda2`, `nbins`, `nepochs` or `interactions` to Ftrl " "constructor, but not both at the same time" == str(e.value))
def test_issue1406(dt0): with pytest.raises(ValueError) as e: noop(dt0[tuple()]) assert "Single-item selectors `DT[col]` are prohibited" in str(e.value) with pytest.raises(ValueError) as e: noop(dt0[(None,)]) assert "Single-item selectors `DT[col]` are prohibited" in str(e.value)
def test_option_bad(): with pytest.raises(AttributeError): noop(dt.options.gooo) with pytest.raises(TypeError) as e: dt.options.register_option(name="gooo", xtype=str, default=3, doc="??") assert "Default value `3` is not of type str" in str(e.value) with pytest.raises(ValueError) as e: dt.options.register_option(name=".hidden", xtype=int, default=0) assert "Invalid option name `.hidden`" in str(e.value) dt.options.register_option(name="gooo", xtype=int, default=3) with pytest.raises(ValueError) as e: dt.options.register_option(name="gooo", xtype=int, default=4, doc="???") assert "Option `gooo` already registered" in str(e.value) with pytest.raises(TypeError) as e: dt.options.gooo = 2.5 assert ("Invalid value for option `gooo`: expected int, instead got float" in str(e.value))
def test_len_wrong_col(): f0 = dt.Frame(range(34)) with pytest.raises(TypeError) as e: noop(f0[:, f[0].len()]) assert ( "Cannot apply function `len()` to a column with stype `int32`" == str( e.value))
def test_issue1406(dt0): with pytest.raises(ValueError) as e: noop(dt0[tuple()]) assert "Invalid tuple of size 0 used as a frame selector" in str(e.value) with pytest.raises(ValueError) as e: noop(dt0[3,]) assert "Invalid tuple of size 1 used as a frame selector" in str(e.value)
def test_join_error_no_left_column(): d0 = dt.Frame(A=[1, 2, 3]) d1 = dt.Frame(B=range(10)) d1.key = "B" with pytest.raises(ValueError) as e: noop(d0[:, :, join(d1)]) assert "Key column `B` does not exist in the left Frame" in str(e.value)
def test_f_col_selector_invalid(): with pytest.raises(TypeError) as e: noop(f[2.5]) assert str(e.value) == ("Column selector should be an integer, string, or " "slice, or list/tuple, not <class 'float'>") # Note: at some point we may start supporting all the expressions below: with pytest.raises(TypeError): noop(f[lambda: 1])
def test_f_int(DT): assert_equals(DT[:, f[3]], DT[:, 3]) assert_equals(DT[:, f[-1]], DT[:, 6]) assert_equals(DT[f[0] > 0, f[-1]], dt.Frame(G=["1", "2"])) with pytest.raises(ValueError) as e: noop(DT[:, f[10]]) assert ("Column index 10 is invalid for a Frame with 7 columns" == str( e.value))
def test_join_error_type_mismatch(): d0 = dt.Frame(A=[1, 2, 3]) d1 = dt.Frame(A=[str(x) for x in range(10)]) d1.key = "A" with pytest.raises(TypeError) as e: noop(d0[:, :, join(d1)]) assert ("Column `A` of type int32 in the left Frame cannot be joined to " "column `A` of incompatible type str32 in the right Frame" in str(e.value))
def test_median_wrong_stype(): DT = dt.Frame(A=["foo"], B=["moo"], stypes={"A": dt.str32, "B": dt.str64}) with pytest.raises(TypeError) as e: noop(DT[:, median(f.A)]) assert ("Unable to apply reduce function median() to a column of " "type str32" in str(e.value)) with pytest.raises(TypeError) as e: noop(DT[:, median(f.B)]) assert ("Unable to apply reduce function median() to a column of " "type str64" in str(e.value))
def test_option_bad(): with pytest.raises(AttributeError): noop(dt.options.gooo) with pytest.raises(ValueError) as e: dt.options.register_option("gooo", str, 3, "??") assert "Default value `3` is not of type str" in str(e.value) with pytest.raises(ValueError) as e: dt.options.register_option(".hidden", int, 0, "") assert "Invalid option name `.hidden`" in str(e.value)
def test_ftrl_construct_wrong_interactions_type(): with pytest.raises(TypeError) as e: noop(Ftrl(interactions=2)) assert ( "Argument `interactions` in Ftrl() constructor should be an iterable, " "instead got <class 'int'>" == str(e.value)) with pytest.raises(TypeError) as e: noop(Ftrl(interactions=["C0"])) assert ( "Argument `interactions` in Ftrl() constructor should be a list of " "lists, instead encountered: 'C0'" == str(e.value))
def test_f_str(DT): assert_equals(DT[:, "B"], DT[:, 1]) assert_equals(DT[:, f.B], DT[:, 1]) assert_equals(DT[:, f["B"]], DT[:, 1]) for i, name in enumerate(DT.names): assert_equals(DT[:, f[name]], DT[:, i]) with pytest.raises(ValueError) as e: noop(DT[:, f["d"]]) assert ("Column `d` does not exist in the Frame; " "did you mean `D`, `A` or `B`?" == str(e.value))
def test_dt_getitem(dt0): dt1 = dt0[:, 0] assert dt1.shape == (4, 1) assert dt1.names == ("A", ) dt1 = dt0[(..., 4)] assert dt1.shape == (4, 1) assert dt1.names == ("E", ) elem2 = dt0[0, 1] assert elem2 is True with pytest.raises(TypeError) as e: noop(dt0[0, 1, 2, 3]) assert "Invalid item at position 2 in DT[i, j, ...] call" == str(e.value)
def test_dt_getitem(dt0): dt1 = dt0[:, 0] assert dt1.shape == (4, 1) assert dt1.names == ("A", ) dt1 = dt0[(..., 4)] assert dt1.shape == (4, 1) assert dt1.names == ("E", ) elem2 = dt0[0, 1] assert elem2 is True with pytest.raises(TypeError) as e: noop(dt0[0, 1, 2, 3]) assert "Invalid item at position 2 in DT[i, j, ...] call" == str(e.value) with pytest.raises(ValueError) as e: noop(dt0["A"]) assert ("Single-item selectors `DT[col]` are prohibited" in str(e.value))
def test_f_col_selector_invalid(): with pytest.raises(TypeError) as e: noop(f[2.5]) assert str(e.value) == ("Column selector should be an integer or a string, " "not <class 'float'>") # Note: at some point we may start supporting all the expressions below: with pytest.raises(TypeError): noop(f[[7, 4]]) with pytest.raises(TypeError): noop(f[("A", "B", "C")]) with pytest.raises(TypeError): noop(f[:3])
def test_jay_all_types(tempfile_jay): d0 = dt.Frame( [[True, False, None, True, True], [None, 1, -9, 12, 3], [4, 1346, 999, None, None], [591, 0, None, -395734, 19384709], [None, 777, 1093487019384, -384, None], [2.987, 3.45e-24, -0.189134e+12, 45982.1, None], [39408.301, 9.459027045e-125, 4.4508e+222, None, 3.14159], ["Life", "Liberty", "and", "Pursuit of Happiness", None], ["кохайтеся", "чорнобриві", ",", "та", "не з москалями"]], stypes=[ dt.bool8, dt.int8, dt.int16, dt.int32, dt.int64, dt.float32, dt.float64, dt.str32, dt.str64 ], names=["b8", "i8", "i16", "i32", "i64", "f32", "f64", "s32", "s64"]) # Force calculation of mins and maxs, so that they get saved into Jay noop(d0.min()) noop(d0.max()) assert len(set(d0.stypes)) == d0.ncols d0.to_jay(tempfile_jay) assert os.path.isfile(tempfile_jay) d1 = dt.fread(tempfile_jay) assert_equals(d0, d1)
def assert_valueerror(frame, rows, error_message): with pytest.raises(ValueError) as e: noop(frame[rows, :]) assert str(e.type) == "<class 'dt.ValueError'>" assert error_message in str(e.value)
def test_dt_stype_heterogenous(dt0): with pytest.raises(ValueError) as e: noop(dt0.stype) assert ("The stype of column 'B' is `bool8`, which is different " "from the stype of the previous column" in str(e.value))
def test_single_element_select_invalid_column(dt0): with pytest.raises(ValueError) as e: noop(dt0[0, "Dd"]) assert ("Column `Dd` does not exist in the Frame; did you mean `D`?" == str(e.value))
def assert_valueerror(frame, rows, error_message): with pytest.raises(ValueError) as e: noop(frame[rows, :]) assert isinstance(e.value, dt.exceptions.DtException) assert error_message in str(e.value)
def test_dt_stype_heterogenous(dt0): with pytest.raises(dt.exceptions.InvalidOperationError) as e: noop(dt0.stype) assert ("The stype of column 'B' is bool8, which is different " "from the stype of the previous column" in str(e.value))
def test_ftrl_construct_wrong_nepochs_type(): with pytest.raises(TypeError) as e: noop(Ftrl(nepochs = 10.0)) assert ("Argument `nepochs` in Ftrl() constructor should be an integer, " "instead got <class 'float'>" == str(e.value))
def assert_typeerror(df, rows, error_message): with pytest.raises(TypeError) as e: noop(df[rows, :]) assert str(e.type) == "<class 'datatable.TypeError'>" assert error_message in str(e.value)
def test_issue1481_3(): DT = dt.Frame(A=range(5)) with pytest.raises(ValueError) as e: noop(DT[:, g.A + 1]) assert ("Column expression references a non-existing join frame" == str( e.value))
def assert_typeerror(frame, cols, error_message): with pytest.raises(TypeError) as e: noop(frame[:, cols]) assert str(e.type) == "<class 'datatable.TypeError'>" assert error_message in str(e.value)
def test_join_error_nokey(): d0 = dt.Frame(A=[1, 2, 3]) d1 = dt.Frame(A=range(10)) with pytest.raises(ValueError) as e: noop(d0[:, :, join(d1)]) assert "The join frame is not keyed" in str(e.value)