Hi Chirag,

A Friday 13 March 2009, Some Indian Bloke escrigué:
> Hi,
>
> Sorry this might seem a little noobish, but I'm just starting out
> with pytables.
>
> I notice that row.fetch_all_fields() returns a Numpy void scalar
> type. Is it possible for it to return a numpy object with at least
> the actual python/numpy sub-types of the fields i.e. int, float, etc.

You can get the numpy types from the void type.  For example, given the 
table:

In [10]: t
Out[10]:
/t (Table(0,)) ''
  description := {
  "col1": Int32Col(shape=(), dflt=0, pos=0),
  "col2": Float64Col(shape=(), dflt=0.0, pos=1)}
  byteorder := 'little'
  chunkshape := (682,)

you can do:

In [14]: r = t.row.fetch_all_fields()

In [17]: r.dtype['col1']
Out[17]: dtype('int32')

In [18]: r.dtype['col2']
Out[18]: dtype('float64')


> Also the Row object seems to be missing the same type information.
> Calling type() on either results in a "TypeError: 'str' object is not
> callable". Is this intensional?

In [19]: type(r)
Out[19]: <type 'numpy.void'>

Mmh, I'm not sure what you mean...

> Is there another way to obtain the 
> type information dynamically(apart from using table.coldtypes or
> table.coltypes) as I will not necessarily know the types of the
> various fields I read from an hdf5 file. I could use ObjectAtom, but
> I'm trying to avoid the overhead. I just want to make sure I haven't
> skipped anything important.
>
> Basically, I want to convert the row object to a python
> object(deserialize) with typed properties automatically and
> vice-versa(serialize). I know python is ducktyped, but I need the
> type information as I'm hoping speed up certain bits of the
> computation using cython or pyrex.

Why you don't like to use Table.coldtypes?  Could you put an example on 
what you are trying to do (a sample script would be ideal)?  At any 
rate, perhaps the slice operator of the Row class could help you:

In [22]: t.row[:]
Out[22]: (0, 0.0)

In [23]: type(t.row[:])
Out[23]: <type 'tuple'>

Cheers,

-- 
Francesc Alted

------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to