From: Francesc A. <fa...@op...> - 2004-02-06 08:47:42
|
Hi Joanna, A Dijous 05 Febrer 2004 02:31, Muench, Joanna va escriure: > I'm running into two problems building the Description classes. The first > is that I won't know until run-time what the size of the arrays I want to > store are. Therefore I need to be able to define the shapes of columns > dynamically before instantiating the Table object. It seems that there > should be a clever way of doing this, but I'm just not seeing it (another > metaclass?). The description parameter of the createTable method (see section 4.4.2 of the user's manual: http://pytables.sourceforge.net/html-doc/usersguide4.html#subsection4.4.2), besides of a IsDescription instance, accept as well a dictionary and a RecArray (from the numarray package) object as metadata descriptors. Use any of these to dinamically specificy the metadata. See http://pytables.sourceforge.net/html-doc/usersguide3.html#section3.3 for an example of that (the "Event" dictionary). In that example, the raw Col() class has been used for defining the properties of columns, but you can use StringCol, IntCol, ... as well. Maybe I should made the example clearer. > > Given that I can figure out how to take care of dynamic sizing, there are > times I will be storing a list of length 1. PyTables doesn't like lists of > length 1. > > An example: > > from tables import * > > LENGTH = 12 > NUM_NAMES = 1 > > class ExampleDescription(IsDescription): > > personId = Int64Col() > ages = Float32Col(shape=LENGTH) > names = StringCol(length=16, shape=NUM_NAMES) > > if I then try to assign exampleRow['names'] = ['fred',] I get a bad value > type. Is this the intended behavior? This is happening because a shape of 1 is interpreted as an scalar (i.e. you should just write: exampleRow['names'] = 'fred'). If you want to pass a list with only one element, use better a shape = (1,). Regards, -- Francesc Alted |