From: Julio T. <jul...@gm...> - 2013-03-22 12:11:17
|
Hi, I just joined this list, I am using PyTables for my project and it works great and fast. I am just trying to optimize some parts of the program and I noticed that zipping the tuples to get one tuple per column takes much longer than reading the data itself. The thing is that readWhere() returns one tuple per row, whereas I I need one tuple per column, so I have to use the zip() function to achieve this. Is there a way to skip this zip() operation? Please see below: def quote_GetData(self, period, name, dt1, dt2): """Returns timedata.Quotes object. Arguments: period -- value from within infogetter.QuotePeriod name -- quote symbol dt1, dt2 -- datetime.datetime or timestamp values """ t = time.time() node = self.quote_GetNode(period, name) ts1 = misc.datetime2timestamp(dt1) ts2 = misc.datetime2timestamp(dt2) L = node.readWhere( \ "(timestamp/1000 >= %f) & (timestamp/1000 <= %f)" % \ (ts1/1000, ts2/1000)) rowNum = len(L) Q = timedata.Quotes() print "%s: took %f seconds to do everything else" % (name, time.time()-t) t = time.time() if rowNum > 0: (Q.timestamp, Q.open, Q.close, Q.high, Q.low, Q.volume, \ Q.numTrades) = zip(*L) print "%s: took %f seconds to ZIP" % (name, time.time()-t) return Q *And the printout:* BOVESPA.VISTA.PETR4: took 0.068788 seconds to do everything else BOVESPA.VISTA.PETR4: took 0.379910 seconds to ZIP |