Hi Jeff, Il 19/01/2012 14:08, Jeff Reback ha scritto: > Hi, > > using the configuration: > > pytables 2.3.1 > numexpr 1.4.1 > python 2.7.1 (on adm64 debian and win64) > > using a readWhere to select rows from a table, if I give a selector with > multiple operands on the index column (e.g. (column > value) & ( column < > value2)) > doesn't seem to work (though works fine with a single operand and on a > non-indexed table) > > in the test output the 4th case (index with start and stop operands), I don't > receive any selection (contrast with the 2nd case which shows non-indexed > behavior) > > is this behavior expected? > > thanks, > > Jeff > > ----------- test script ----------- > > #!/usr/local/bin/python > > import tables > import numpy as np > import datetime, time > > # create table > def create(name, add_index = False): > test_file = "%s.hdf" % name > handle = tables.openFile(test_file, "w") > > table = handle.createTable(handle.root, 'table', dict( > index = tables.Time64Col(), > column = tables.StringCol(25), > values = tables.FloatCol(shape=(3)), > )) > > # add data > date = datetime.datetime(2011,1,1,8,0,0) > > r = table.row > for i in xrange(100): > r['index'] = time.mktime((date + > datetime.timedelta(days=i)).timetuple()) > r['column'] = ("str-%d" % (i % 5)) > r['values'] = np.arange(3) > r.append() > table.flush() > > if add_index: > col = table.cols._f_col('index') > col.createIndex(filters = None) > > handle.close() > return test_file > > def select(name, start, stop = None): > """ start and stop are dates """ > > test_file = "%s.hdf" % name > handle = tables.openFile(test_file,"r") > selectors = [] > > # index selector > selectors.append("(index >= %s)" % time.mktime(start.timetuple())) > if stop is not None: > selectors.append("(index <= %s)" % time.mktime(stop.timetuple())) > > # column selector > selectors.append("((column == 'str-0') | (column == 'str-1'))") > > selector = ' & '.join(selectors) > > print "selector -> [f->%s,start->%s,stop->%s] --> %s" % > (test_file,start,stop,selector) > ans = getattr(handle.root,'table').readWhere(selector) > print "ans -> %s" % ans > handle.close() > > > # no indexing > create('no_index',add_index = False) > select('no_index', start = datetime.datetime(2011,2,1,0,0,0)) > select('no_index', start = datetime.datetime(2011,2,1,0,0,0), stop = > datetime.datetime(2011,3,1,0,0,0)) > > # with indexing > create('with_index',add_index = True) > select('with_index', start = datetime.datetime(2011,2,1,0,0,0)) > select('with_index', start = datetime.datetime(2011,2,1,0,0,0), stop = > datetime.datetime(2011,3,1,0,0,0)) > > ------ptdump -v on the no_index.hdf-------- > [cow-jreback-/tmp] ptdump -v no_index.hdf > / (RootGroup) '' > /table (Table(100,)) '' > description := { > "column": StringCol(itemsize=25, shape=(), dflt='', pos=0), > "index": Time64Col(shape=(), dflt=0.0, pos=1), > "values": Float64Col(shape=(3,), dflt=0.0, pos=2)} > byteorder := 'little' > chunkshape := (1149,) > > ------ ptdump -v on the with_index.hdf -------- > > [cow-jreback-/tmp] ptdump -v with_index.hdf > / (RootGroup) '' > /table (Table(100,)) '' > description := { > "column": StringCol(itemsize=25, shape=(), dflt='', pos=0), > "index": Time64Col(shape=(), dflt=0.0, pos=1), > "values": Float64Col(shape=(3,), dflt=0.0, pos=2)} > byteorder := 'little' > chunkshape := (1149,) > autoIndex := True > colindexes := { > "index": Index(6, medium, shuffle, zlib(1)).is_CSI=False} > > --------test output ------- > selector -> [f->no_index.hdf,start->2011-02-01 00:00:00,stop->None] --> > (index >= 1296536400.0) & ((column == 'str-0') | (column == 'str-1')) > ans -> [('str-1', 1296565200.0, [0.0, 1.0, 2.0]) > ('str-0', 1296910800.0, [0.0, 1.0, 2.0]) > ('str-1', 1296997200.0, [0.0, 1.0, 2.0]) > ('str-0', 1297342800.0, [0.0, 1.0, 2.0]) > ('str-1', 1297429200.0, [0.0, 1.0, 2.0]) > ('str-0', 1297774800.0, [0.0, 1.0, 2.0]) > ('str-1', 1297861200.0, [0.0, 1.0, 2.0])
[CUT] IMHO your problem is related to a known issue [1]. Can you please confirm? I linked your message to the issue but please feel free to add additional info. thanks for reporting. We will try to fix the issue ASAP. best regards [1] https://github.com/PyTables/PyTables/issues/119 -- Antonio Valentino ------------------------------------------------------------------------------ Keep Your Developer Skills Current with LearnDevNow! The most comprehensive online learning library for Microsoft developers is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3, Metro Style Apps, more. Free future releases when you subscribe now! http://p.sf.net/sfu/learndevnow-d2d _______________________________________________ Pytables-users mailing list Pytables-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pytables-users