def testDoubleColumnames(self): ex = None try: colnames = ["col0", "col0", "col1", "col1", "col2"] Table(colnames, [int] * 5, [""] * 5) except Exception, e: ex = e.message
def testDynamicColumnAttributes(self): t = Table(["a", "b", "c"], [str, int, int], ["%s", "%d", "%d"], []) t.a t.b t.c assert len(t.a.values) == 0 assert len(t.b.values) == 0 assert len(t.c.values) == 0 t.renameColumns(dict(a="aa")) assert "a" not in t.getColNames() assert "aa" in t.getColNames() t.aa try: t.a raise Exception("t.a should be deteted") except: pass col = pickle.loads(pickle.dumps(t.aa)) assert len(col.values) == 0 t.dropColumns("aa") assert "aa" not in t.getColNames() try: t.aa raise Exception("t.aa should be deteted") except: pass
def setupTable(): names = "int long float str object array".split() types = [ int, long, float, str, object, np.ndarray, ] formats = ["%3d", "%d", "%.3f", "%s", "%r", "'array(%r)' % o.shape"] row1 = [1, 12323L, 1.0, "hi", {1: 1}, np.array((1, 2, 3))] row2 = [2, 22323L, 2.0, "hi2", [ 2, 3, ], np.array(((2, 3, 4), (1, 2, 3)))] row3 = [ 3, 32323L, 3.0, "hi3", (3, ), np.array(((3, 3, 4, 5), (1, 2, 3, 4))) ] rows = [row1, row2, row3] t = Table(names, types, formats, rows, "testtabelle", meta=dict(why=42)) t = t.extractColumns("int", "float", "str") t.addEnumeration() t._name = "t" t._print() return t
def testIfThenElse(self): t = Table(["a", "b", "c"], [str, int, int], ["%s", "%d", "%d"], []) t.rows.append(["0", 1, 2]) t.rows.append([None, 2, 1]) t._print() t.addColumn("x", (t.a.isNotNone()).thenElse(t.b, t.c)) assert t.getColNames() == ["a", "b", "c", "x"] print t._print() t.addColumn("y", (t.a.isNotNone()).thenElse("ok", "not ok")) t._print() assert t.y.values == ("ok", "not ok")
def testToOpenMSFeatureMap(): t = Table("mz rt".split(), [float, float], 2 * ["%.6f"]) fm = t.toOpenMSFeatureMap() assert fm.size() == 0 t.addRow([1.0, 2.0]) fm = t.toOpenMSFeatureMap() assert fm.size() == 1 f = fm[0] assert f.getMZ() == 1.0 # == ok, as no digits after decimal point assert f.getRT() == 2.0 # dito
def testSomePredicates(self): #build table names = "int long float str object array".split() types = [ int, long, float, str, object, np.ndarray, ] formats = ["%3d", "%d", "%.3f", "%s", "%r", "'array%r' % (o.shape,)"] row1 = [1, 12323L, 1.0, "hi", {1: 1}, np.array((1, 2, 3))] row2 = [ 2, 22323L, 2.0, "hi2", [ 2, 3, ], np.array(((2, 3, 4), (1, 2, 3))) ] row3 = [ 3, 32323L, 3.0, "hi3", (3, ), np.array(((3, 3, 4, 5), (1, 2, 3, 4))) ] rows = [row1, row2, row3] t = Table(names, types, formats, rows, "testtabelle", meta=dict(why=42)) expr = (t.int + t.float).inRange(-1, 2) tn = t.filter(expr) assert len(tn) == 1 assert tn.getValue(tn.rows[0], "int") == 1 tn = t.filter((t.float + t.int).inRange(-1, 2)) assert len(tn) == 1 assert tn.getValue(tn.rows[0], "int") == 1 tn = t.filter(t.float.approxEqual(1.0, t.int / 10)) tn._print() assert len(tn) == 1, len(tn) assert tn.getValue(tn.rows[0], "int") == 1
def testDetectionOfUnallowdColumnNames(self): ex = None try: Table(["__init__"], [int], ["%d"]) except Exception, e: ex = e.message
ex = None try: tn.addRow([1, 2, 3, 2]) except Exception, e: ex = e assert ex is not None ex = None try: tn.addRow(["a", 1, 2]) except Exception, e: ex = e assert ex is not None with self.assertRaises(Exception): Table(["a"], [np.float32], ["%f"], [[32.0]]) #build table names = "int long float str object array".split() types = [ int, long, float, str, object, np.ndarray, ] formats = ["%3d", "%d", "%.3f", "%s", "%r", "'array(%r)' % (o.shape,)"] row1 = [1, 12323L, 1.0, "hi", {1: 1}, np.array((1, 2, 3))] row2 = [
def testIllegalRows(): with pytest.raises(Exception): Table(["a", "b"], [float, float], ["%f", "%f"], [(1, 2)])