Skip to content

Instantly share code, notes, and snippets.

@joshmoore
Created April 26, 2012 17:44
Show Gist options
  • Save joshmoore/2501251 to your computer and use it in GitHub Desktop.
Save joshmoore/2501251 to your computer and use it in GitHub Desktop.
Reproduce the Time64Column indexing issue
import tables
import random
class Descr(tables.IsDescription):
Awhen = tables.Time32Col(pos = 1)
value = tables.Float32Col(pos = 2)
h5f = tables.openFile('alan.h5', 'w')
tbl = h5f.createTable('/', 'test', Descr)
tbl.cols.Awhen.createIndex(_verbose = True)
t = 1321031471.0 # 11/11/11 11:11:11
tbl.append([(t + i, random.random()) for i in range(10)])
tbl.flush()
def query(msg, s):
print "%s" % msg,
print '\thas_index=', tbl.cols.Awhen.is_indexed,
print '\tuse_index=%30s' % tbl.willQueryUseIndexing(s),
print '\twhere=',len([(row['Awhen'], row['value']) for row in tbl.where(s)]),
print '\treadWhere=',len(tbl.readWhere(wherestr))
wherestr = '(Awhen >= %d) & (Awhen < %d)'%(t, t+5)
query("Initial index: verbose ", wherestr)
tbl.cols.Awhen.removeIndex()
query("remove index ", wherestr)
tbl.cols.Awhen.createIndex(_verbose = False)
query("re-add index (non-verbose)", wherestr)
tbl.cols.Awhen.removeIndex()
query("remove again ", wherestr)
tbl.cols.Awhen.createIndex(_verbose = True)
tbl.flush()
query("re-add index (with flush) ", wherestr)
tbl.cols.Awhen.removeIndex()
tbl.cols.Awhen.createIndex(kind="full")
tbl.flush()
query("re-add index (full) ", wherestr)
tbl.cols.Awhen.removeIndex()
tbl.cols.Awhen.createIndex(kind="ultralight")
tbl.flush()
query("re-add index (ultralight) ", wherestr)
tbl.cols.Awhen.removeIndex()
tbl.cols.Awhen.createIndex(optlevel=0)
tbl.flush()
query("re-add index (o=0) ", wherestr)
tbl.cols.Awhen.removeIndex()
tbl.cols.Awhen.createIndex(optlevel=9)
tbl.flush()
query("re-add index (o=9) ", wherestr)
tbl.reIndex()
query("re-index ", wherestr)
tbl.cols.value.createIndex()
query("also index value ", wherestr)
#h5f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment