From: travlr <vel...@gm...> - 2005-09-07 07:32:21
|
Hi all, In a previous thread, I discussed with Fransesc about being able to incorporate non-sequential indexing arrays (key arrays) in the following ways: select and get (or set values) tables.Table.Table <rows>=20 select and get (or set values) tables.Table.Column <items> select and get (or set values) tables.Array <items> via: object[key] =3D value(s) I was able to use the patch Fransesc had provided, and also (with my extremely limited expertise) a little more including using Numeric arrays and Python lists for the keys (all getting/setting intended except enabling the tables.Array[key] functionality). Unfortunately, I at some point accidently erased the damn file :-( Today, I went back and got the "selecting and getting" Table <rows> and Column <elements> for versions 1.0 and 1.1 working again, The attachments provided are a tables.Table.dif file for each version. Below is an example of it's usage. I was not able to do any more especially for the newer versions. I am hoping for this functionality, as well as being able to set the values via... keys of a non-sequential index_array: tables.Table[index_array] =3D value(s); and tables.Column[index_array] =3D value(s); and tables.Array[index_array] =3D value(s) Also Fransesc, two questions: 1) Could the tables.Table.Column also have an .nrows (nelements) attribute? 2) Once bounded, tables.Table used to return as a <class 'numarray.records.RecArray'> object. Now it returns a <class 'tables.nestedrecords.NestedRecArray'> object....Is this necessary?. Thank You ############# EXAMPLE ########### import tables as ta import numarray as na # test_file is one of my actual files (renamed) hfile =3D ta.openFile('~/data/h5/test_folder/test_file.h5','a') # These are pointers to tables.Table=20 # objects (not bounded or returned) mtable =3D hfile.root.d_050808.d_050808 mcolumn =3D mtable.cols.A1 # mtable is a tables.Table.Table of a=20 # particular day in my database. print print 'type(mtable)........ ',type(mtable) print 'mtable.nrows....... ',mtable.nrows print 'type(mcolumn).... ',type(mcolumn) # NOTE to Francesc: Why no nrows (nelements) for columns? #### print 'mcolumn.nrows... ',mcolumn.nrows # This will return an non-sequential index=20 # smaller than the table's (or column's)=20 # original index index =3D na.where(mcolumn[:]=3D=3D2)[0] print print 'index.size....... ', index.size() # The non-sequential index is applied # To the tables.Table and and tables.Table.Column # and returns a numarray.records object (or an array object=20 # for the column) with the specified indexing rtable =3D mtable[index] rcolumn =3D mcolumn[index] print print 'type(rtable)..... ',type(rtable) print 'rtable.size()..... ',rtable.size() print 'rcolumn.size()..',rcolumn.size() hfile.close() ############# RESULT ########### /usr/bin/python -u "~/scripts/september/testForPytables.py" type(mtable)........ <class 'tables.Table.Table'> mtable.nrows....... 105983 type(mcolumn).... <class 'tables.Table.Column'> index.size....... 1172 type(rtable)..... <class 'tables.nestedrecords.NestedRecArray'> rtable.size()..... 1172 rcolumn.size().. 1172 |