How to use the datatable.f.A function in datatable

To help you get started, we’ve selected a few datatable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github h2oai / datatable / tests / test-groups.py View on Github external
def test_groups2a():
    DT0 = dt.Frame(A=[1, 2, 1], B=[3, 4, 5])
    DT1 = DT0[:, [f.A, f.B, f.A + f.B], by("A")]
    assert_equals(DT0, dt.Frame(A=[1, 2, 1], B=[3, 4, 5]))
    assert_equals(DT1, dt.Frame([[1, 1, 2], [1, 1, 2], [3, 5, 4], [4, 6, 6]],
                                names=["A", "A.0", "B", "C0"]))
github h2oai / datatable / tests / test_f.py View on Github external
def test_columnset_sum(DT):
    assert_equals(DT[:, f[int].extend(f[float])], DT[:, [int, float]])
    assert_equals(DT[:, f[:3].extend(f[-3:])], DT[:, [0, 1, 2, -3, -2, -1]])
    assert_equals(DT[:, f.A.extend(f.B)], DT[:, ['A', 'B']])
    assert_equals(DT[:, f[:].extend({"extra": f.A + f.C})],
                  dt.cbind(DT, DT[:, {"extra": f.A + f.C}]))
github h2oai / datatable / tests / munging / test_delete.py View on Github external
def test_del_cols_computed2():
    d0 = smalldt()
    with pytest.raises(TypeError) as e:
        del d0[:, [f.A, f.B, f.A + f.B]]
    assert ("Item 2 in the `j` selector list is a computed expression and "
            "cannot be deleted" == str(e.value))
github h2oai / datatable / tests / ijby / test-assign-frame.py View on Github external
def test_assign_frame_to_filtered_rows():
    DT = dt.Frame(A=range(5))
    DT[f.A < 3, "A"] = dt.Frame([4, 5, 7])
    assert_equals(DT, dt.Frame(A=[4, 5, 7, 3, 4]))
github h2oai / datatable / tests / munging / test_str.py View on Github external
def test_re_match_bad_regex3():
    with pytest.raises(ValueError):
        noop(dt.Frame(["abc"])[f.A.re_match("???"), :])
    # assert ("Invalid regular expression: One of *?+{ was not preceded by a "
github h2oai / datatable / tests / munging / test_replace.py View on Github external
def test_replace_str64_2():
    Y = dt.Frame([["a"], [0]], names=["A", "B"], stypes=["str64", "int32"])
    Y[f.B < 100, f.A] = "hello"
    frame_integrity_check(Y)
    assert Y.stypes == (dt.str64, dt.int32)
    assert Y.to_list() == [["hello"], [0]]
github h2oai / datatable / tests / test_tocsv.py View on Github external
def test_issue2253():
    X = dt.Frame(A=[10, 20])
    X["B"] = dt.f.A > 15
    assert X.to_csv() == "A,B\n" + "10,0\n" + "20,1\n"
github h2oai / datatable / tests / munging / test_dt_combo.py View on Github external
def test_columns_rows():
    df0 = dt.Frame([range(10), range(0, 20, 2)], names=["A", "B"],
                   stype=stype.int32)
    assert df0.shape == (10, 2)

    df1 = df0[::2, f.A + f.B]
    df2 = df0[::2, :][:, f.A + f.B]
    frame_integrity_check(df1)
    frame_integrity_check(df2)
    assert df1.to_list() == [[0, 6, 12, 18, 24]]
    assert df2.to_list() == [[0, 6, 12, 18, 24]]

    df3 = df0[::-2, {"res": f.A * f.B}]
    df4 = df0[::2, :][::-1, :][:, f.A * f.B]
    frame_integrity_check(df3)
    frame_integrity_check(df4)
    assert df3.to_list() == [[162, 98, 50, 18, 2]]
github h2oai / datatable / tests / ijby / test-assign.py View on Github external
def test_assign_list_duplicates():
    DT = dt.Frame(A=range(5))
    with pytest.warns(DatatableWarning) as ws:
        DT[:, ["B", "B"]] = [f.A + 1, f.A + 2]
    frame_integrity_check(DT)
    assert DT.names == ("A", "B", "B.0")
    assert DT.to_list() == [[0, 1, 2, 3, 4], [1, 2, 3, 4, 5], [2, 3, 4, 5, 6]]
    assert len(ws) == 1
    assert ("Duplicate column name found, and was assigned a unique name: "
            "'B' -> 'B.0'" in ws[0].message.args[0])
github h2oai / datatable / tests / test_dt_sort.py View on Github external
def test_int8_small_stable():
    d0 = dt.Frame([
        [5, 3, 5, None, 100, None, 3, None],
        [1, 5, 10, 20, 50, 100, 200, 500]
    ], names=["A", "B"])
    d1 = d0[:, :, sort(f.A)]
    frame_integrity_check(d1)
    assert d1.to_list() == [
        [None, None, None, 3, 3, 5, 5, 100],
        [20, 100, 500, 5, 200, 1, 10, 50],
    ]