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
def test_hdf5_table_appender(table, tmpdir): path = tmpdir.join("test.hdf5").strpath to_hdf5(table, path, atomic=True) append_to_hdf5([table, table, table], path) path = tmpdir.join("test_2.hdf5").strpath to_hdf5(table, path, atomic=False) append_to_hdf5([table, table, table], path, atomic=False)
def tproxy(table): folder = tempfile.mkdtemp() path = os.path.join(folder, "t.hdf5") to_hdf5(table, path) tproxy = Hdf5TableProxy(path) yield tproxy tproxy.close()
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)
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)
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)