Hey Curious, I think that is probably because str do not have defined size on their own.
Both numpy and pytables need to know the number of bytes something a variable is expected to have. By default, dtypes do a good job of guessing size, but you are overriding the default behavior and not supplying the length of the string. Try using dtype formatting strings instead of relying on the type. Be Well Anthony On Thu, Jun 2, 2011 at 8:03 PM, Curiouslearn <curiousle...@gmail.com> wrote: > Hi All, > > I am using pytables to store data in hdf5 format. Each table in the > hdf5 file has many user defined attributes. > > For example: > > Suppose the table name is: thistab > It has user defined attributes some of which are floats, some are ints > and some are strings. > > For the float (and int) attributes, the following works: > > datatype = {"names": ["Floatattr1", "Floatattr2"], > "formats": > [type(tab.attrs.__getattr__("Floatattr1")), > > type(tab.attrs.__getattr__("Floatattr2")) ]} > nparray = np.zeros(10, dtype = datatype) > > However, if I try the same for the String attribute it does not work. > If I try the following: > > datatype = {"names": ["Stringattr1", "Floatattr2"], > "formats": > [type(tab.attrs.__getattr__("Floatattr1")), > > type(tab.attrs.__getattr__("Floatattr2")) ]} > nparray = np.zeros(10, dtype = datatype) > > I get > > TypeError: data type not understood > > Any suggestions for how I can make this work - I want to specify the > numpy array datatype by reading the type > from table attributes. > > Thanks in advance for your help. > > > ------------------------------------------------------------------------------ > Simplify data backup and recovery for your virtual environment with > vRanger. > Installation's a snap, and flexible recovery options mean your data is > safe, > secure and there when you need it. Discover what all the cheering's about. > Get your free trial download today. > http://p.sf.net/sfu/quest-dev2dev2 > _______________________________________________ > Pytables-users mailing list > Pytables-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/pytables-users >
------------------------------------------------------------------------------ Simplify data backup and recovery for your virtual environment with vRanger. Installation's a snap, and flexible recovery options mean your data is safe, secure and there when you need it. Discover what all the cheering's about. Get your free trial download today. http://p.sf.net/sfu/quest-dev2dev2
_______________________________________________ Pytables-users mailing list Pytables-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pytables-users