Exemplo n.º 1
0
def test_fromhdf5sorted():
    
    # set up a new hdf5 table to work with
    h5file = openFile("test1.h5", mode="w", title="Test file")
    h5file.createGroup('/', 'testgroup', 'Test Group')
    class FooBar(IsDescription):
        foo = Int32Col(pos=0)
        bar = StringCol(6, pos=2)
    h5table = h5file.createTable('/testgroup', 'testtable', FooBar, 'Test Table')
    
    # load some data into the table
    table1 = (('foo', 'bar'),
              (3, 'asdfgh'),
              (2, 'qwerty'),
              (1, 'zxcvbn'))
    for row in table1[1:]:
        for i, f in enumerate(table1[0]):
            h5table.row[f] = row[i]
        h5table.row.append()
    h5table.cols.foo.createCSIndex()
    h5file.flush()
    
    # verify we can get the data back out
    table2 = fromhdf5sorted(h5table, sortby='foo')
    ieq(sort(table1, 'foo'), table2)
    ieq(sort(table1, 'foo'), table2)

    # clean up    
    h5file.close()
Exemplo n.º 2
0
          (2, 'qwerty'),
          (1, 'zxcvbn'))

for row in table1[1:]:
    for i, f in enumerate(table1[0]):
        h5table.row[f] = row[i]
    h5table.row.append()

h5table.cols.foo.createCSIndex() # CS index is required
h5file.flush()
h5file.close()

# access the data, sorted by the indexed column
from petl import look
from petlx.hdf5 import fromhdf5sorted
table2 = fromhdf5sorted('test1.h5', '/testgroup', 'testtable', sortby='foo')
look(table2)


# tohdf5
table1 = (('foo', 'bar'),
          (1, 'asdfgh'),
          (2, 'qwerty'),
          (3, 'zxcvbn'))

from petl import look
look(table1)
from petlx.hdf5 import tohdf5, fromhdf5
tohdf5(table1, 'test1.h5', '/testgroup', 'testtable', create=True, createparents=True)
look(fromhdf5('test1.h5', '/testgroup', 'testtable'))
Exemplo n.º 3
0
# load some data into the table
table1 = (('foo', 'bar'), (3, 'asdfgh'), (2, 'qwerty'), (1, 'zxcvbn'))

for row in table1[1:]:
    for i, f in enumerate(table1[0]):
        h5table.row[f] = row[i]
    h5table.row.append()

h5table.cols.foo.createCSIndex()  # CS index is required
h5file.flush()
h5file.close()

# access the data, sorted by the indexed column
from petl import look
from petlx.hdf5 import fromhdf5sorted
table2 = fromhdf5sorted('test1.h5', '/testgroup', 'testtable', sortby='foo')
look(table2)

# tohdf5
table1 = (('foo', 'bar'), (1, 'asdfgh'), (2, 'qwerty'), (3, 'zxcvbn'))

from petl import look
look(table1)
from petlx.hdf5 import tohdf5, fromhdf5
tohdf5(table1,
       'test1.h5',
       '/testgroup',
       'testtable',
       create=True,
       createparents=True)
look(fromhdf5('test1.h5', '/testgroup', 'testtable'))