Exemplo n.º 1
0
def test_ymd_wrong_types():
    DT = dt.Frame(A=[2000], B=[2.1], C=[1])

    msg = "The year column at index 0 is of type float64, integer expected"
    with pytest.raises(TypeError, match=msg):
        DT[:, ymd(f.B, f.A, f.C)]

    msg = "The month column at index 0 is of type float64, integer expected"
    with pytest.raises(TypeError, match=msg):
        DT[:, ymd(f.A, f.B, f.C)]

    msg = "The day column at index 0 is of type float64, integer expected"
    with pytest.raises(TypeError, match=msg):
        DT[:, ymd(f.A, f.C, f.B)]
Exemplo n.º 2
0
def test_invalid_dates():
    DT = dt.Frame(Y=[2000, 2001, 2002, 2003, 2004],
                  M=[1, 2, 3, 4, 5],
                  D=[-1, 0, 1, 100, 100000])
    assert_equals(DT[:, ymd(f.Y, 2, 29)],
                  dt.Frame([d(2000, 2, 29), None, None, None,
                            d(2004, 2, 29)]))
    assert_equals(
        DT[:, ymd(2020, f.M, 31)],
        dt.Frame([d(2020, 1, 31), None,
                  d(2020, 3, 31), None,
                  d(2020, 5, 31)]))
    assert_equals(DT[:, ymd(2020, 1, f.D)],
                  dt.Frame([None, None, d(2020, 1, 1), None, None]))
Exemplo n.º 3
0
def test_ymd_simple():
    DT = dt.Frame(Y=[2001, 2003, 2005, 2020],
                  M=[1, 5, 4, 11],
                  D=[12, 18, 30, 1])
    RES = DT[:, ymd(f.Y, f.M, f.D)]
    assert_equals(
        RES,
        dt.Frame(
            [d(2001, 1, 12),
             d(2003, 5, 18),
             d(2005, 4, 30),
             d(2020, 11, 1)]))
Exemplo n.º 4
0
def test_ymd_named():
    DT = dt.Frame(Y=[2001, 2002, 2003], M=[3, 9, 1], D=[31, 3, 1])
    RES = DT[:, ymd(month=f.M, day=f.D, year=f.Y)]
    assert_equals(RES, dt.Frame([d(2001, 3, 31),
                                 d(2002, 9, 3),
                                 d(2003, 1, 1)]))
Exemplo n.º 5
0
def test_invalid_months():
    DT = dt.Frame(range(5))
    assert_equals(DT[:, ymd(2021, f[0], 1)],
                  dt.Frame([None] + [d(2021, i, 1) for i in range(1, 5)]))