How to use the datatable.fread 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 / fread / test_fread_api.py View on Github external
def test_fread_from_glob(tempfile):
    base, ext = os.path.splitext(tempfile)
    if not ext:
        ext = ".csv"
    pattern = base + "*" + ext
    tempfiles = ["".join([base, str(i), ext]) for i in range(10)]
    try:
        for j in range(10):
            with open(tempfiles[j], "w") as f:
                f.write("A,B,C\n0,0,0\n%d,%d,%d\n"
                        % (j, j * 2 + 1, (j + 3) * 17 % 23))
        res = dt.fread(pattern)
        assert len(res) == 10
        assert set(res.keys()) == set(tempfiles)
        for f in res.values():
            assert isinstance(f, dt.Frame)
            frame_integrity_check(f)
            assert f.names == ("A", "B", "C")
            assert f.shape == (2, 3)
        df = dt.rbind(*[res[f] for f in tempfiles])
        frame_integrity_check(df)
        assert df.names == ("A", "B", "C")
        assert df.shape == (20, 3)
        assert df.to_list() == [
            [0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9],
            [0, 1, 0, 3, 0, 5, 0, 7, 0, 9, 0, 11, 0, 13, 0, 15, 0, 17, 0, 19],
            [0, 5, 0, 22, 0, 16, 0, 10, 0, 4, 0, 21, 0, 15, 0, 9, 0, 3, 0, 20]
        ]
github h2oai / datatable / tests / fread / test_fread_small.py View on Github external
def test_numbers_with_quotes1():
    d0 = dt.fread('B,C\n'
                  '"12"  ,15\n'
                  '"13"  ,18\n'
                  '"14"  ,3')
    frame_integrity_check(d0)
    assert d0.shape == (3, 2)
    assert d0.ltypes == (dt.ltype.int, dt.ltype.int)
    assert d0.names == ("B", "C")
    assert d0.to_list() == [[12, 13, 14], [15, 18, 3]]
github h2oai / datatable / tests / fread / test_fread_small.py View on Github external
def test_fread2():
    f = dt.fread("""
        A,B,C,D
        1,2,3,4
        10,0,,7.2
        ,1,12,3.3333333333
        """)
    assert f.shape == (3, 4)
    assert f.names == ("A", "B", "C", "D")
    assert f.ltypes == (ltype.int, ltype.int, ltype.int, ltype.real)
github h2oai / datatable / tests / fread / test_fread_issues.py View on Github external
def test_issue_R2222():
    d0 = dt.fread("A,B\n999,1\n999,2\n", na_strings=["999", "NA"])
    d1 = dt.fread("A,B\n999,1\n4,2\n", na_strings=["999", "NA"])
    d2 = dt.fread("A,B\n999,5\n999,999\n", na_strings=["999", "NA"])
    d3 = dt.fread("A,B\n999,1\n999,2\n", na_strings=["99", "NA"])
    frame_integrity_check(d0)
    assert d0.to_list() == [[None, None], [1, 2]]
    assert d1.to_list() == [[None, 4], [1, 2]]
    assert d2.to_list() == [[None, None], [5, None]]
    assert d3.to_list() == [[999, 999], [1, 2]]
github h2oai / datatable / tests / munging / test_rbind.py View on Github external
def test_rbind_mmapped(tempfile_jay):
    dt0 = dt.Frame({"A": [1, 5, 7], "B": ["one", "two", None]})
    dt0.to_jay(tempfile_jay)
    del dt0
    dt1 = dt.fread(tempfile_jay)
    dt2 = dt.Frame({"A": [-1], "B": ["zero"]})
    dt1.rbind(dt2)
    dtr = dt.Frame({"A": [1, 5, 7, -1], "B": ["one", "two", None, "zero"]})
    assert_equals(dt1, dtr)
github h2oai / datatable / tests / fread / test_fread_small.py View on Github external
def test_float_ext_literals4():
    d0 = dt.fread("D\n1.\n1.#SNAN\n1.#QNAN\n1.#IND\n1.#INF\n")
    frame_integrity_check(d0)
    assert d0.ltypes == (ltype.real, )
    assert d0.to_list() == [[1, None, None, None, math.inf]]
github h2oai / datatable / tests / fread / test_fread_small.py View on Github external
def test_float_ext_literals6():
    d0 = dt.fread("F\n1.1\n+1.3333333333333\n5.9e320\n45609E11\n-0890.e-03\n")
    frame_integrity_check(d0)
    assert d0.ltypes == (ltype.real, )
    assert d0.to_list() == [[1.1, 1.3333333333333, 5.9e320, 45609e11, -0.890]]
github h2oai / datatable / tests / fread / test_fread_api.py View on Github external
def test_sep_invalid3():
    with pytest.raises(Exception) as e:
        dt.fread("A,,B\n", sep="⌘")
    assert ("Multi-character or unicode separators are not supported: '⌘'"
            in str(e.value))
github h2oai / datatable / tests / fread / test_fread_small.py View on Github external
def test_numbers_with_quotes2():
    d0 = dt.fread('A,B\n'
                  '83  ,"23948"\n'
                  '55  ,"20487203497"')
    frame_integrity_check(d0)
    assert d0.shape == (2, 2)
    assert d0.ltypes == (dt.ltype.int, dt.ltype.int)
    assert d0.names == ("A", "B")
    assert d0.to_list() == [[83, 55], [23948, 20487203497]]
github h2oai / driverlessai-recipes / transformers / augmentation / is_ramadan.py View on Github external
def get_ramadan_dates():
    return dt.fread(
        """	
        DateStart,DateEnd