Hi Toby, A Wednesday 15 April 2009, Toby Mathieson escrigué: > Hi there, > > I am trying to figure out a simple way to remove data from a HDF5 > when it matches certain criteria (analogous to SQL 'delete from table > where = %s'. I am probably being stupid, but I cannot find a > straightforward way to do this! I couldn't see anyway to do this in > the tutorial, except for using the row numbers directly. > > So far I have done the following: > > rows2delete = [] > for thisid in idlist: > rows = [x.nrow for x in table.where('id==%r' %thisid)] > > rows2delete+=rows > print 'todelete', rows2delete > for r in rows2delete: > print 'r', r > table.removeRows(r) > > > This always crashes thus: > > File > "/bio/shared/auxsoft/python-2.5.2/lib/python2.5/site-packages/tables/ >table.py", line 2129, in removeRows > (start, stop, step) = self._processRangeRead(start, stop, 1) > File > "/bio/shared/auxsoft/python-2.5.2/lib/python2.5/site-packages/tables/ >leaf.py", line 459, in _processRangeRead > "number of rows (%s)" % (start, nrows) ) > IndexError: start of range (7545) is greater than number of rows > (7544) > > > as though the removeRows(r) was removing all data after r....
This is because you have built a list of rows first and then started to remove them one by one. However, after you remove the first row, the row count for the other rows to be deleted changes, so the successive removeRows() operations are deleting the wrong rows, ultimately causing an attempt to delete non-existent rows. So the error raised is the intended behaviour (in fact, it is fortunate that you saw it, as it is saying that something went wrong with your delete rows procedure). > has any one come across and fixed this? Or know what's going on? The removeRows() method always rewrite the part of the table after the deleted rows completely (which is quite inneficient for your case). Instead, I'd suggest you to use the whereAppend() method so as to select the desired rows in destination. Then it's only a matter of removing the original table and doing a rename of the new table to the original name afterwards. HTH, -- Francesc Alted "One would expect people to feel threatened by the 'giant brains or machines that think'. In fact, the frightening computer becomes less frightening if it is used only to simulate a familiar noncomputer." -- Edsger W. Dykstra "On the cruelty of really teaching computer science" ------------------------------------------------------------------------------ This SF.net email is sponsored by: High Quality Requirements in a Collaborative Environment. Download a free trial of Rational Requirements Composer Now! http://p.sf.net/sfu/www-ibm-com _______________________________________________ Pytables-users mailing list Pytables-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pytables-users