示例#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()
示例#2
0
def collapsedintervals(tbl, start='start', stop='stop', facet=None):
    """
    Utility function to collapse intervals in a table. 
    
    If no facet key is given, returns an iterator over `(start, stop)` tuples.
    
    If facet key is given, returns an iterator over `(key, start, stop)` tuples.  
    
    .. versionadded:: 0.5.5
    
    """
    
    if facet is None:
        tbl = sort(tbl, key=start)
        for iv in _collapse(values(tbl, (start, stop))):
            yield iv
    else:
        tbl = sort(tbl, key=(facet, start))
        for k, g in rowgroupby(tbl, key=facet, value=(start, stop)):
            for iv in _collapse(g):
                yield (k,) + iv