A Thursday 16 April 2009, Toby Mathieson escrigué:
> Hi Francesc,
>
> Thanks for the hint - I avoided doing this because the number of
> records to delete was a very small fraction of those to keep (10 out
> of ~50,000)  and it seems a bit superfluous to have to copy all
> records not to be deleted to another table and then rename.  (it also
> takes quite a while, since I have to scan through the 49,990 good ids
> to keep!) ...  and then following this I have to recreated a load of
> indexes on the new table.  Is this really only way to perform this
> delete?

As I said before, deleting a row (or range of rows) does imply a whole 
table copy (well, more exactly, a copy of the rows after the row to be 
deleted), so this is why I was suggesting the whereAppend() method.  

But in case you want to keep using removeRows() you can, as long as you 
correct the number of the row to be deleted after each iteration.  
Something like this should work:

In [7]: rows2delete = [3,2,5,1]

In [8]: tmp = np.array(rows2delete)

In [9]: tmp.sort()

In [10]: rows2delete_corrected = tmp - np.arange(len(tmp))

In [11]: rows2delete_corrected
Out[11]: array([1, 1, 1, 2])

So, in rows2delete_corrected you have the correct sequence to be used in 
your removal loop:

         for r in rows2delete_corrected:
             print 'r', r
             table.removeRows(r)

> Many thanks for your help so far ..!

Cheers,

-- 
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"

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to