Beispiel #1
0
    def testUniqueNotNone(self):

        t = toTable("a", [1,1,None])
        assert t.a.uniqueNotNone() == 1

        t = toTable("a", [1,1,1])
        assert t.a.uniqueNotNone() == 1

        t.addColumn("b", None)
        t._print()
        with self.assertRaises(Exception):
            t.b.uniqueNotNone()
        t.addColumn("c", [None, 1,2 ])
        with self.assertRaises(Exception):
            t.c.uniqueNotNone()

        t.addColumn("d", [1,2, 2 ])
        with self.assertRaises(Exception):
            t.d.uniqueNotNone()

        with self.assertRaises(Exception):
            t.addColumn("d", [2,3,4])

        with self.assertRaises(Exception):
            t.addConstantColumn("d", 3)

        t2 = toTable("x",[])
        with self.assertRaises(Exception):
            t.aggregate(t2.x.mean, "neu")
Beispiel #2
0
    def test_all_comps(self):
        a = toTable("a",[3,2,1])
        b = toTable("b",[1,2,3]) # must be sorted for tests below !

        def _test(e, a=a, b=b):

            a.join(b, e).print_()

            t1 = a.join(b, a.a <= b.b).rows
            t2 = a.join(b, b.b >= a.a).rows
            t3 = b.join(a, a.a <= b.b).rows
            t4 = b.join(a, b.b >= a.a).rows

            b.sortBy("b")
            a.join(b, e).print_()
            s1 = a.join(b, a.a <= b.b).rows
            s2 = a.join(b, b.b >= a.a).rows
            s3 = b.join(a, a.a <= b.b).rows
            s4 = b.join(a, b.b >= a.a).rows

            assert t1 == t2
            assert t3 == t4
            assert t1 == s1
            assert t2 == s2
            assert t3 == s3
            assert t4 == s4

            b.join(a, e).print_()

            t1 = a.join(b, a.a <= b.b).rows
            t2 = a.join(b, b.b >= a.a).rows
            t3 = b.join(a, a.a <= b.b).rows
            t4 = b.join(a, b.b >= a.a).rows

            b.sortBy("b")
            b.join(a, e).print_()
            s1 = a.join(b, a.a <= b.b).rows
            s2 = a.join(b, b.b >= a.a).rows
            s3 = b.join(a, a.a <= b.b).rows
            s4 = b.join(a, b.b >= a.a).rows

            assert t1 == t2
            assert t3 == t4
            assert t1 == s1
            assert t2 == s2
            assert t3 == s3
            assert t4 == s4

        _test(a.a <= b.b)
        _test(a.a < b.b)
        _test(a.a >= b.b)
        _test(a.a > b.b)
        _test(a.a == b.b)
        _test(a.a != b.b)
Beispiel #3
0
    def testCompress(self):
        t = toTable("a", [])
        import numpy
        t.compressPeakMaps()

        s = Spectrum(numpy.arange(12).reshape(-1,2), 1.0, 1, "+")
        pm = PeakMap([s])
        s = Spectrum(numpy.arange(12).reshape(-1,2), 1.0, 1, "+")
        pm2 = PeakMap([s])

        t = toTable("pm", [pm, pm2])
        assert len(set(map(id, t.pm.values))) == 2
        t.compressPeakMaps()
        assert len(set(map(id, t.pm.values))) == 1
Beispiel #4
0
def test_small():

    if not emzed.core.config.global_config.get("metlin_token"):
        raise Exception("please provide EMZED_METLIN_TOKEN variable "\
                        "on commandline for running test")

    t = utils.toTable("m0",[195.0877, 194.07904])
    tn = utils.matchMetlin(t, "m0", ["M"], 30)
    assert len(tn) == 23
    assert len(set(tn.formula__0.values)) == 5
    t = utils.toTable("m0",[195.0877, ])
    tn = utils.matchMetlin(t, "m0", ["M", "M+H"], 30)
    assert len(tn) == 23
    assert len(set(tn.formula__0.values)) == 5
Beispiel #5
0
    def test_numpy_comparison(self):
        return 
        v = np.array((1,2,3))
        t = toTable("a",[v])
        t.print_()
        t2 = t.filter(t.a == t.a)
        assert len(t2) == len(t)
        t2 = t.filter(t.a <= t.a)
        assert len(t2) == len(t)
        t2 = t.filter(t.a >= t.a)
        assert len(t2) == len(t)
        t2 = t.filter(t.a != t.a)
        assert len(t2) == 0
        t2 = t.filter(t.a < t.a)
        assert len(t2) == 0
        t2 = t.filter(t.a > t.a)
        assert len(t2) == 0

        t2 = t.filter(t.a == 3)
        assert len(t2) == 0
        t2 = t.filter(t.a <= 3)
        assert len(t2) == 1
        t2 = t.filter(t.a >= 1)
        assert len(t2) == 1
        t2 = t.filter(t.a != 3)
        assert len(t2) == 0
        t2 = t.filter(t.a < 4)
        assert len(t2) == 1
        t2 = t.filter(t.a > 0)
        assert len(t2) == 1
Beispiel #6
0
    def testSplitBy(self):
        t = toTable("a", [1,1,3,4])
        t.addColumn("b", [1,1,3,3])
        t.addColumn("c", [1,2,1,4])
        t._print()
        subts = t.splitBy("a")
        assert len(subts) == 3
        res = Table.mergeTables(subts)
        assert len(res) == len(t)
        subts[0]._print()
        assert res.a.values == t.a.values
        assert res.b.values == t.b.values
        assert res.c.values == t.c.values

        # check if input tables are not altered
        for subt in subts:
            assert subt.getColNames() == [ "a", "b", "c"]

        subts = t.splitBy("a", "c")
        assert len(subts) == 4
        res = Table.mergeTables(subts)
        assert res.a.values == t.a.values
        assert res.b.values == t.b.values
        assert res.c.values == t.c.values

        # check if input tables are not altered
        for subt in subts:
            assert subt.getColNames() == [ "a", "b", "c"]
Beispiel #7
0
    def testRename(self):
        t = toTable("a", [1,1,3,4])
        t.addColumn("b", [1,1,3,3])
        t.addColumn("c", [1,2,1,4])
        with self.assertRaises(Exception):
            t.renameColumns(dict(d="e"))

        with self.assertRaises(Exception):
            t.renameColumns(a="b")

        with self.assertRaises(Exception):
            t.renameColumns(a="x", b="x")

        with self.assertRaises(Exception):
            t.renameColumns(dict(a="f"), a="d")

        t.renameColumns(dict(a="x"), dict(c="z"), b="y")
        assert tuple(t.getColNames()) == ("x", "y", "z")

        t.renameColumn("x", "a")
        assert tuple(t.getColNames()) == ("a", "y", "z")
        t.renameColumn("y", "b")
        assert tuple(t.getColNames()) == ("a", "b", "z")
        t.renameColumn("z", "c")
        assert tuple(t.getColNames()) == ("a", "b", "c")
Beispiel #8
0
def table():

    peaks_0 = np.arange(20.0).reshape(-1, 2)
    peaks_1 = np.arange(30.0).reshape(-1, 2)

    spec_0 = Spectrum(peaks_0[:], 30.0, 1, "+")
    spec_1 = Spectrum(peaks_1[:], 30.0, 2, "+", [(10, 1000, 0)])
    spec_2 = Spectrum(peaks_1[:], 40.0, 1, "+")

    pm = PeakMap([spec_0, spec_1, spec_2])

    t0 = toTable("int", (None, 2, 3, 3, None), type_=int)
    t0.addColumn("float", (1.0, 2.0, 4.0, 3.0, None), type_=float)
    t0.addColumn("bool", (True, False, None, True, False), type_=bool)
    t0.addColumn("check", (True, False, None, True, False), type_=CheckState)
    t0.addColumn("str", ("1", "2" * 100, None, "a", "b"), type_=str)
    t0.addColumn("object", ({1}, dict(a=2), None, (1,), [1, 2]), type_=object)
    t0.addColumn("peakmap", pm, type_=PeakMap)
    t0.addColumn("i1", [1, None, 2, None, 3], type_=int)
    t0.addColumn("i2", [None, 1, None, 2, None], type_=int)

    n = 10
    ts_0 = TimeSeries(map(datetime.fromordinal, range(1, n + 1)), range(n), "label1")
    ts_0.x[3] = None
    ts_0.y[3] = np.nan

    n = 10
    ts_1 = TimeSeries(map(datetime.fromordinal, range(1000,  n + 1000)),
                      range(1000, 1000 + n), "label2", [bool(i % 4) for i in range(n)])

    t0.addColumn("time_series", [ts_0, ts_0, ts_1, ts_1, None], type_=TimeSeries)

    t0.meta = {"a": "b"}
    return t0
Beispiel #9
0
    def test_apply_with_none_values_as_result(self):

        t = toTable("a", [1,2,3])

        dd = {1:1, 2: 4, 3:5}
        t.addColumn("b", t.a.apply(dd.get))
        assert t.b.values == (1, 4, 5,)
        t.dropColumns("b")

        dd = {1: 4}
        t.addColumn("b", t.a.apply(dd.get))
        assert t.b.values == (4, None, None,)
        t.dropColumns("b")

        dd = {2: 4}
        t.addColumn("b", t.a.apply(dd.get))
        assert t.b.values == (None, 4, None,)
        t.dropColumns("b")

        dd = {3: 4}
        t.addColumn("b", t.a.apply(dd.get))
        assert t.b.values == (None, None, 4,)
        t.dropColumns("b")

        dd = {2: 4, 3:5}
        t.addColumn("b", t.a.apply(dd.get))
        assert t.b.values == (None, 4, 5,)
        t.dropColumns("b")
Beispiel #10
0
def test_perm():
    t = toTable("a", (1, 1, 2, 2, None), type_=int)
    t.addColumn("d", (4, 4, 2, 1, None), type_=str)
    to_hdf5(t, "abc.hdf5")

    prox = Hdf5TableProxy("abc.hdf5")

    t = prox.toTable()

    perm = prox.sortPermutation(("a", "d"), (True, True))
    print(t[perm])

    perm = prox.sortPermutation(("a", "d"), (False, True))
    print(t[perm])

    perm = prox.sortPermutation(("a", "d"), (True, False))
    print(t[perm])

    perm = prox.sortPermutation(("a", "d"), (False, False))
    print(t[perm])

    perm = prox.sortPermutation("a", True)
    print(perm)
    print(t[perm])

    perm = prox.sortPermutation("a", False)
    print(perm)
    print(t[perm])
Beispiel #11
0
def proxy_small_table(tmpdir):
    t = toTable("a", (1, 1, 2, 2, None), type_=int)
    t.addColumn("d", ("4", "4", "2", "1", None), type_=str)
    path = tmpdir.join("test.hdf5").strpath
    to_hdf5(t, path)

    prox = Hdf5TableProxy(path)
    return prox
Beispiel #12
0
def test_large():
    if not emzed.core.config.global_config.get("metlin_token"):
        raise Exception("please provide EMZED_METLIN_TOKEN variable "\
                        "on commandline for running test")

    mz_values = [185.0877 + i +1 for i in range(100)]
    t = utils.toTable("m0", mz_values)
    tn = utils.matchMetlin(t, "m0", ["M", "M+H", "M+2H", "M+3H"], 3)
    assert len(tn) >= 2709, len(tn)
Beispiel #13
0
    def testApply(self):

        t = toTable("a", [0.01, 0.1, 0.1, 0.015, 0.2,1.0 ])

        t.addColumn("a_bin", t.a.apply(lambda v: int(v*100)))
        # this returned numpy-ints due to an fault in addColumn and so
        # we got 6 tables instead of 4:
        ts = t.splitBy("a_bin")
        assert len(ts) == 4
Beispiel #14
0
    def testWithEmtpyTablesAndTestColnameGeneration(self):
        e = toTable("x", [])
        f = toTable("y", [])
        g = toTable("z", [1])

        assert len(e.filter(e.x == 0)) == 0
        t1 = e.join(f, f.y == e.x)
        assert len(t1) == 0
        assert t1.getColNames() == ["x", "y__0"], t1.getColNames()
        t1 = e.join(f, e.x == f.y)
        assert len(t1) == 0
        assert t1.getColNames() == ["x", "y__0"], t1.getColNames()

        t1 = e.join(g, g.z == e.x)
        assert len(t1) == 0
        assert t1.getColNames() == ["x", "z__0"], t1.getColNames()
        t1 = e.join(g, e.x == g.z)
        assert len(t1) == 0
        assert t1.getColNames() == ["x", "z__0"], t1.getColNames()


        t1 = g.join(e, e.x == g.z)
        assert len(t1) == 0
        assert t1.getColNames() == ["z", "x__0"], t1.getColNames()
        t1 = g.join(e, g.z == e.x)
        assert len(t1) == 0
        assert t1.getColNames() == ["z", "x__0"], t1.getColNames()

        t1 = e.leftJoin(f, f.y == e.x)
        assert len(t1) == 0
        assert t1.getColNames() == ["x", "y__0"], t1.getColNames()
        t1 = e.leftJoin(g, g.z == e.x)
        assert len(t1) == 0
        assert t1.getColNames() == ["x", "z__0"], t1.getColNames()
        t1 = g.leftJoin(e, e.x == g.z)
        assert len(t1) == 1
        assert t1.getColNames() == ["z", "x__0"], t1.getColNames()
        assert t1.rows[0] ==  [1, None]

        t1.print_()
        f.print_()
        t2 = t1.leftJoin(f, f.y == t1.x__0)
        assert t2.getColNames() ==["z", "x__0", "y__1"], t2.getColNames()
        assert len(t2) == 1
Beispiel #15
0
    def testMerge(self):
        t1 = toTable("a", [1])
        t1.addColumn("b", [2])
        t1.addColumn("c", [3])

        t2 = toTable("a", [1,2])
        t2.addColumn("c", [1,3])
        t2.addColumn("d", [1,4])

        tn = Table.mergeTables([t1, t2])

        assert tn.a.values == (1, 1, 2,)
        assert tn.b.values == (2, None, None,)
        assert tn.c.values == (3, 1, 3,)
        assert tn.d.values == (None, 1, 4,)

        # check if input tables are not altered
        assert t1.getColNames() == [ "a", "b", "c"]
        assert t2.getColNames() == [ "a", "c", "d"]
Beispiel #16
0
def test_write_unicode(tmpdir, regtest):

    table = toTable("a", ("x", None, u"", "", u"ccccäää##c"), type_=unicode)
    table.addColumn("b", ("x", "asbcder", None, None, ""), type_=str)
    table.addColumn("c", ("x", "asbcder", 1, (1,), ""), type_=object)
    path = tmpdir.join("t.hdf5").strpath
    to_hdf5(table, path)
    prox = Hdf5TableProxy(path)
    print(prox.toTable(), file=regtest)
    print(prox.reader.get_col_values("a"), file=regtest)
    print(prox.reader.get_col_values("b"), file=regtest)
    print([i.load() for i in prox.reader.get_col_values("c")], file=regtest)
Beispiel #17
0
def test_tables():
    ip = RInterpreter()
    t = toTable("a", [1, 2])

    # transfer Table tor R:
    ip.t = t

    # fetch Table from R
    assert ip.execute("s <- t").s.rows == t.rows

    # fetch pandas.DataFrame from R
    df = ip.get_raw("s")
    assert df.as_matrix().tolist() == [[1], [2]]
Beispiel #18
0
 def testSomeExpressions(self):
     t = toTable("mf", ["Ag", "P", "Pb", "P3Pb", "PbP"])
     tn = t.filter(t.mf.containsElement("P"))
     assert len(tn) == 3
     tn = t.filter(t.mf.containsElement("Pb"))
     assert len(tn) == 3
     tn = t.filter(t.mf.containsOnlyElements("Pb"))
     assert len(tn) == 1
     tn = t.filter(t.mf.containsOnlyElements("PPb"))
     assert len(tn) == 4
     tn = t.filter(t.mf.containsOnlyElements(["Pb"]))
     assert len(tn) == 1
     tn = t.filter(t.mf.containsOnlyElements(["P", "Pb"]))
     assert len(tn) == 4
Beispiel #19
0
def test_round_trip_objects(tmpdir, regtest):
    # test roundtrip:
    col = [{i: i + 1} for i in range(5)]
    t0 = toTable("dicts", col, type_=object)

    col = [{i: i + 2} for i in range(5)]
    t0.addColumn("dicts_1", col, type_=object)
    t0.addColumn("strs", map(str, range(5)), type_=str)
    t0.addColumn("strs_1", t0.strs * 3 + "_x", type_=str)

    print(t0, file=regtest)
    path = tmpdir.join("test.hdf5").strpath
    to_hdf5(t0, path)
    tproxy = Hdf5TableProxy(path)

    tback = tproxy.toTable()
    print(tback, file=regtest)
def test_table_full(regtest):

    t = toTable("names", ("uwe", "schmit"), type_=str)
    t.addColumn("idx", (1, 2), type_=int)
    t.addColumn("mass", (1.0, 1.11), type_=float)
    t.addColumn("class", (True, False), type_=bool)

    ip = RInterpreter()
    ip.t = t

    print >> regtest, t
    print >> regtest, ip.t
    print >> regtest, ip.get_df_as_table("t")
    print >> regtest, ip.get_df_as_table("t", types=dict(idx=long))

    print >> regtest, map(type, t._colNames)
    print >> regtest, map(type, ip.t._colNames)
    print >> regtest, t._colTypes
    print >> regtest, ip.t._colTypes
def _test_tables(ip, regtest):
    t = toTable("a", [1, 2])

    # transfer Table tor R:
    ip.t = t

    # fetch Table from R
    assert ip.execute("s <- t").s.rows == t.rows

    # fetch pandas.DataFrame from R
    df = ip.get_raw("s")
    assert df.as_matrix().tolist() == [[1], [2]]

    df = ip.get_raw("mtcars")
    print >> regtest, df

    ip.ddf = df

    print >> regtest, ip.ddf
    print >> regtest, ip.mtcars
Beispiel #22
0
def test_table_in_tables(tmpdir, regtest):
    t = toTable("id", [1, 1, 2], type_=int)
    t.addColumn("a", [1, 2, 3], type_=int)
    t.addColumn("b", [3, 4, 5], type_=int)
    table = t.collapse("id", efficient=False)

    print(table, file=regtest)
    print(table.collapsed[0], file=regtest)
    print(table.collapsed[0], file=regtest)

    path = tmpdir.join("test.hdf5").strpath
    writer = Hdf5TableWriter(path)
    writer.write_table(table)
    writer.close()

    proxy = Hdf5TableProxy(path)
    from_hdf5 = proxy.toTable()
    print(from_hdf5, file=regtest)
    print(from_hdf5.collapsed[0], file=regtest)
    print(from_hdf5.collapsed[0], file=regtest)

    assert table.uniqueId() == from_hdf5.uniqueId()
Beispiel #23
0
    def testWithNoneValues(self):

        # simple int compare ###################################
        t = toTable("a", [None, 2])
        t.print_()

        assert len(t.filter(t.a < 3)) == 1

        t2 = t.copy()
        assert len(t.join(t2, t.a==t2.a)) == 1
        t.leftJoin(t2, t.a==t2.a).print_()

        assert len(t.leftJoin(t2, t.a==t2.a)) == 2

        assert len(t.join(t2, t.a<=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a<t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2

        assert len(t.join(t2, t.a!=t2.a)) == 0
        assert len(t.leftJoin(t2, t.a!=t2.a)) == 2

        assert len(t.join(t2, t.a>=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a>t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2

        t.sortBy("a")

        assert len(t.join(t2, t.a==t2.a)) == 1
        assert len(t.leftJoin(t2, t.a==t2.a)) == 2

        assert len(t.join(t2, t.a<=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a<t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2

        assert len(t.join(t2, t.a!=t2.a)) == 0
        assert len(t.leftJoin(t2, t.a!=t2.a)) == 2

        assert len(t.join(t2, t.a>=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a>t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2

        t.sortBy("a", ascending=False)

        assert len(t.join(t2, t.a==t2.a)) == 1
        assert len(t.leftJoin(t2, t.a==t2.a)) == 2

        assert len(t.join(t2, t.a<=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a<t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2

        assert len(t.join(t2, t.a!=t2.a)) == 0
        assert len(t.leftJoin(t2, t.a!=t2.a)) == 2

        assert len(t.join(t2, t.a>=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a>t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2


        t = toTable("a", [None, 2.0])
        t.print_()

        assert len(t.filter(t.a < 3)) == 1

        t2 = t.copy()
        assert len(t.join(t2, t.a==t2.a)) == 1
        assert len(t.leftJoin(t2, t.a==t2.a)) == 2

        assert len(t.join(t2, t.a<=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a<t2.a)) == 0
        # simple float compare ##################################
        t.print_()
        t2.print_()
        t.leftJoin(t2, t.a<t2.a).print_()
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2


        t.join(t2, t.a!=t2.a).print_()
        assert len(t.join(t2, t.a!=t2.a)) == 0
        assert len(t.leftJoin(t2, t.a!=t2.a)) == 2

        assert len(t.join(t2, t.a>=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a>t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2


        t.sortBy("a", ascending=True)

        assert len(t.join(t2, t.a==t2.a)) == 1
        assert len(t.leftJoin(t2, t.a==t2.a)) == 2

        assert len(t.join(t2, t.a<=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a<t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2


        t.join(t2, t.a!=t2.a).print_()
        assert len(t.join(t2, t.a!=t2.a)) == 0
        assert len(t.leftJoin(t2, t.a!=t2.a)) == 2

        assert len(t.join(t2, t.a>=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a>t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2

        t.sortBy("a", ascending=False)

        assert len(t.join(t2, t.a==t2.a)) == 1
        assert len(t.leftJoin(t2, t.a==t2.a)) == 2

        assert len(t.join(t2, t.a<=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a<t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2


        t.join(t2, t.a!=t2.a).print_()
        assert len(t.join(t2, t.a!=t2.a)) == 0
        assert len(t.leftJoin(t2, t.a!=t2.a)) == 2

        assert len(t.join(t2, t.a>=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a>t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2

        # simple str compare ###################################
        t = toTable("a", [None, "2"])
        t.filter(t.a < "3").print_()

        assert len(t.filter(t.a < "3")) == 1

        t2 = t.copy()
        assert len(t.join(t2, t.a==t2.a)) == 1
        assert len(t.leftJoin(t2, t.a==t2.a)) == 2

        assert len(t.join(t2, t.a<=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a<t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2


        t.join(t2, t.a!=t2.a).print_()
        assert len(t.join(t2, t.a!=t2.a)) == 0
        assert len(t.leftJoin(t2, t.a!=t2.a)) == 2

        assert len(t.join(t2, t.a>=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a>t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2

        t.sortBy("a", ascending=True)
        assert len(t.join(t2, t.a==t2.a)) == 1
        assert len(t.leftJoin(t2, t.a==t2.a)) == 2

        assert len(t.join(t2, t.a<=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a<t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2


        t.join(t2, t.a!=t2.a).print_()
        assert len(t.join(t2, t.a!=t2.a)) == 0
        assert len(t.leftJoin(t2, t.a!=t2.a)) == 2

        assert len(t.join(t2, t.a>=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a>t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2

        t.sortBy("a", ascending=False)
        assert len(t.join(t2, t.a==t2.a)) == 1
        assert len(t.leftJoin(t2, t.a==t2.a)) == 2

        assert len(t.join(t2, t.a<=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a<t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2


        t.join(t2, t.a!=t2.a).print_()
        assert len(t.join(t2, t.a!=t2.a)) == 0
        assert len(t.leftJoin(t2, t.a!=t2.a)) == 2

        assert len(t.join(t2, t.a>=t2.a)) == 1
        assert len(t.leftJoin(t2, t.a<=t2.a)) == 2

        assert len(t.join(t2, t.a>t2.a)) == 0
        assert len(t.leftJoin(t2, t.a<t2.a)) == 2


        # simple float compare reversed #########################
        t = toTable("a", [None, 2.0])
        t.print_()

        assert len(t.filter(3.0 > t.a)) == 1
        assert len(t.filter(3.0 >= t.a)) == 1
        assert len(t.filter(3.0 == t.a)) == 0
        assert len(t.filter(3.0 < t.a)) == 0
        assert len(t.filter(3.0 <= t.a)) == 0
        assert len(t.filter(3.0 != t.a)) == 1
        assert len(t.filter(3 > t.a)) == 1
        assert len(t.filter(3 >= t.a)) == 1
        assert len(t.filter(3 == t.a)) == 0
        assert len(t.filter(3 < t.a)) == 0
        assert len(t.filter(3 <= t.a)) == 0
        assert len(t.filter(3 != t.a)) == 1

        t.sortBy("a")
        t.print_()
        t.filter(3 > t.a).print_()
        assert len(t.filter(3 > t.a)) == 1
        assert len(t.filter(3 >= t.a)) == 1
        assert len(t.filter(3 == t.a)) == 0
        assert len(t.filter(3 < t.a)) == 0
        assert len(t.filter(3 <= t.a)) == 0
        assert len(t.filter(3 != t.a)) == 1
        assert len(t.filter(3.0 > t.a)) == 1
        assert len(t.filter(3.0 >= t.a)) == 1
        assert len(t.filter(3.0 == t.a)) == 0
        assert len(t.filter(3.0 < t.a)) == 0
        assert len(t.filter(3.0 <= t.a)) == 0
        assert len(t.filter(3.0 != t.a)) == 1

        t.sortBy("a", ascending=False)
        assert len(t.filter(3 > t.a)) == 1
        assert len(t.filter(3 >= t.a)) == 1
        assert len(t.filter(3 == t.a)) == 0
        assert len(t.filter(3 < t.a)) == 0
        assert len(t.filter(3 <= t.a)) == 0
        assert len(t.filter(3 != t.a)) == 1
        assert len(t.filter(3.0 > t.a)) == 1
        assert len(t.filter(3.0 >= t.a)) == 1
        assert len(t.filter(3.0 == t.a)) == 0
        assert len(t.filter(3.0 < t.a)) == 0
        assert len(t.filter(3.0 <= t.a)) == 0
        assert len(t.filter(3.0 != t.a)) == 1

        # simple int   compare reversed #########################
        t = toTable("a", [None, 2])
        t.print_()

        assert len(t.filter(3 > t.a)) == 1
        assert len(t.filter(3 >= t.a)) == 1
        assert len(t.filter(3 == t.a)) == 0
        assert len(t.filter(3 < t.a)) == 0
        assert len(t.filter(3 <= t.a)) == 0
        assert len(t.filter(3 != t.a)) == 1

        assert len(t.filter(3.0 > t.a)) == 1
        assert len(t.filter(3.0 >= t.a)) == 1
        assert len(t.filter(3.0 == t.a)) == 0
        assert len(t.filter(3.0 < t.a)) == 0
        assert len(t.filter(3.0 <= t.a)) == 0
        assert len(t.filter(3.0 != t.a)) == 1

        t.sortBy("a")
        assert len(t.filter(3 > t.a)) == 1
        assert len(t.filter(3 >= t.a)) == 1
        assert len(t.filter(3 == t.a)) == 0
        assert len(t.filter(3 < t.a)) == 0
        assert len(t.filter(3 <= t.a)) == 0
        assert len(t.filter(3 != t.a)) == 1

        assert len(t.filter(3.0 > t.a)) == 1
        assert len(t.filter(3.0 >= t.a)) == 1
        assert len(t.filter(3.0 == t.a)) == 0
        assert len(t.filter(3.0 < t.a)) == 0
        assert len(t.filter(3.0 <= t.a)) == 0
        assert len(t.filter(3.0 != t.a)) == 1

        t.sortBy("a", ascending=False)
        assert len(t.filter(3 > t.a)) == 1
        assert len(t.filter(3 >= t.a)) == 1
        assert len(t.filter(3 == t.a)) == 0
        assert len(t.filter(3 < t.a)) == 0
        assert len(t.filter(3 <= t.a)) == 0
        assert len(t.filter(3 != t.a)) == 1

        assert len(t.filter(3.0 > t.a)) == 1
        assert len(t.filter(3.0 >= t.a)) == 1
        assert len(t.filter(3.0 == t.a)) == 0
        assert len(t.filter(3.0 < t.a)) == 0
        assert len(t.filter(3.0 <= t.a)) == 0
        assert len(t.filter(3.0 != t.a)) == 1

        # simple str   compare reversed #########################
        t = toTable("a", [None, "2"])
        t.print_()

        assert len(t.filter("3" > t.a)) == 1
        assert len(t.filter("3" >= t.a)) == 1
        assert len(t.filter("3" == t.a)) == 0
        assert len(t.filter("3" < t.a)) == 0
        assert len(t.filter("3" <= t.a)) == 0
        assert len(t.filter("3" != t.a)) == 1

        t.sortBy("a")
        assert len(t.filter("3" > t.a)) == 1
        assert len(t.filter("3" >= t.a)) == 1
        assert len(t.filter("3" == t.a)) == 0
        assert len(t.filter("3" < t.a)) == 0
        assert len(t.filter("3" <= t.a)) == 0
        assert len(t.filter("3" != t.a)) == 1

        t.sortBy("a", ascending=False)
        assert len(t.filter("3" > t.a)) == 1
        assert len(t.filter("3" >= t.a)) == 1
        assert len(t.filter("3" == t.a)) == 0
        assert len(t.filter("3" < t.a)) == 0
        assert len(t.filter("3" <= t.a)) == 0
        assert len(t.filter("3" != t.a)) == 1

        ##########################################################

        t = toTable("i", [1,2,None])
        assert len(t.filter(t.i.isNone())) == 1
        assert len(t.filter(t.i.isNotNone())) == 2

        t.addColumn("b", [2,3,None])
        assert t.getColNames() == ["i", "b"]
        t.replaceColumn("b", t.b+1)

        assert t.getColNames() == ["i", "b"]

        t.addRow([None, None])
        t.addRow([3, None])
        t.addRow([3, 3.0])
        assert t.b.values == ( 3, 4, None, None, None, 3)

        # check order
        t.replaceColumn("i", t.i)
        assert t.getColNames() == ["i", "b"]

        s = toTable("b",[])
        x = t.join(s, t.b == s.b)
        assert len(x) == 0

        assert s.b.max() == None
Beispiel #24
0
 def testConstantColumn(self):
     t = toTable("a",[1,2,3])
     t.addConstantColumn("b", dict())
     assert len(set(id(x) for x in t.b.values)) == 1
Beispiel #25
0
 def testSlicing(self):
     t = toTable("a", [1, 2, 3])
     assert t[0].a.values == (1,)
     assert t[:1].a.values == (1,)
     assert t[1:].a.values == (2, 3,)
     assert t[:].a.values == (1, 2, 3,)
Beispiel #26
0
 def testUpdateColumn(self):
     t = toTable("a", [1, 2])
     t.updateColumn("a", t.a + 1)
     assert t.a.values == (2, 3,)
     t.updateColumn("b", t.a + 1)
     assert t.b.values == (3, 4,)