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])
('str-0', 1298206800.0, [0.0, 1.0, 2.0])
('str-1', 1298293200.0, [0.0, 1.0, 2.0])
('str-0', 1298638800.0, [0.0, 1.0, 2.0])
('str-1', 1298725200.0, [0.0, 1.0, 2.0])
('str-0', 1299070800.0, [0.0, 1.0, 2.0])
('str-1', 1299157200.0, [0.0, 1.0, 2.0])
('str-0', 1299502800.0, [0.0, 1.0, 2.0])
('str-1', 1299589200.0, [0.0, 1.0, 2.0])
('str-0', 1299934800.0, [0.0, 1.0, 2.0])
('str-1', 1300017600.0, [0.0, 1.0, 2.0])
('str-0', 1300363200.0, [0.0, 1.0, 2.0])
('str-1', 1300449600.0, [0.0, 1.0, 2.0])
('str-0', 1300795200.0, [0.0, 1.0, 2.0])
('str-1', 1300881600.0, [0.0, 1.0, 2.0])
('str-0', 1301227200.0, [0.0, 1.0, 2.0])
('str-1', 1301313600.0, [0.0, 1.0, 2.0])
('str-0', 1301659200.0, [0.0, 1.0, 2.0])
('str-1', 1301745600.0, [0.0, 1.0, 2.0])
('str-0', 1302091200.0, [0.0, 1.0, 2.0])
('str-1', 1302177600.0, [0.0, 1.0, 2.0])]
selector -> [f->no_index.hdf,start->2011-02-01 00:00:00,stop->2011-03-01 
00:00:00] --> (index >= 1296536400.0) & (index <= 1298955600.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])
('str-0', 1298206800.0, [0.0, 1.0, 2.0])
('str-1', 1298293200.0, [0.0, 1.0, 2.0])
('str-0', 1298638800.0, [0.0, 1.0, 2.0])
('str-1', 1298725200.0, [0.0, 1.0, 2.0])]
selector -> [f->with_index.hdf,start->2011-02-01 00:00:00,stop->None] --> 
(index >= 1296536400.0) & ((column == 'str-0') | (column == 'str-1'))
ans      -> [('str-0', 1293886800.0, [0.0, 1.0, 2.0])
('str-1', 1293973200.0, [0.0, 1.0, 2.0])
('str-0', 1294318800.0, [0.0, 1.0, 2.0])
('str-1', 1294405200.0, [0.0, 1.0, 2.0])
('str-0', 1294750800.0, [0.0, 1.0, 2.0])
('str-1', 1294837200.0, [0.0, 1.0, 2.0])
('str-0', 1295182800.0, [0.0, 1.0, 2.0])
('str-1', 1295269200.0, [0.0, 1.0, 2.0])
('str-0', 1295614800.0, [0.0, 1.0, 2.0])
('str-1', 1295701200.0, [0.0, 1.0, 2.0])
('str-0', 1296046800.0, [0.0, 1.0, 2.0])
('str-1', 1296133200.0, [0.0, 1.0, 2.0])
('str-0', 1296478800.0, [0.0, 1.0, 2.0])
('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])
('str-0', 1298206800.0, [0.0, 1.0, 2.0])
('str-1', 1298293200.0, [0.0, 1.0, 2.0])
('str-0', 1298638800.0, [0.0, 1.0, 2.0])
('str-1', 1298725200.0, [0.0, 1.0, 2.0])
('str-0', 1299070800.0, [0.0, 1.0, 2.0])
('str-1', 1299157200.0, [0.0, 1.0, 2.0])
('str-0', 1299502800.0, [0.0, 1.0, 2.0])
('str-1', 1299589200.0, [0.0, 1.0, 2.0])
('str-0', 1299934800.0, [0.0, 1.0, 2.0])
('str-1', 1300017600.0, [0.0, 1.0, 2.0])
('str-0', 1300363200.0, [0.0, 1.0, 2.0])
('str-1', 1300449600.0, [0.0, 1.0, 2.0])
('str-0', 1300795200.0, [0.0, 1.0, 2.0])
('str-1', 1300881600.0, [0.0, 1.0, 2.0])
('str-0', 1301227200.0, [0.0, 1.0, 2.0])
('str-1', 1301313600.0, [0.0, 1.0, 2.0])
('str-0', 1301659200.0, [0.0, 1.0, 2.0])
('str-1', 1301745600.0, [0.0, 1.0, 2.0])
('str-0', 1302091200.0, [0.0, 1.0, 2.0])
('str-1', 1302177600.0, [0.0, 1.0, 2.0])]
selector -> [f->with_index.hdf,start->2011-02-01 00:00:00,stop->2011-03-01 
00:00:00] --> (index >= 1296536400.0) & (index <= 1298955600.0) & ((column == 
'str-0') | (column == 'str-1'))
ans      -> []
------------------------------------------------------------------------------
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

Reply via email to