A Tuesday 12 October 2010 01:25:20 Grace Li escrigué:
> Hi all,
> 
> I read in the pytables user manual that description field of the
> method tables.createTable can be a numpy array object and that if the
> numpy array has data, the data will be directly appended into the
> table created.
> I was trying to do this for my data which is written in a txt file,
> but encountered problems.
> 
> First I used numpy.genfromtxt to create a numpy ndarray holding all
> the data (the data is basically a homogeneous array with integer
> types for the columns).
> Then I passed this array object by doing
> 
> data = genfromtxt('a.txt', dtype=None)  # setting dype=None lets
> genfromtxt automatically determine data types
> #assume that h5file object exists
> h5file.createTable('my_group', 'my_data', description=data)
> 
> I get this exception:
> 
>     table = h5file.createTable(my_group', 'my_data',
> description=data) File
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/sit
> e-packages/tables-2.2.1.dev-py2.6-macosx-10.6-fat.egg/tables/file.py"
> , line 761, in createTable
>     chunkshape=chunkshape, byteorder=byteorder)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/sit
> e-packages/tables-2.2.1.dev-py2.6-macosx-10.6-fat.egg/tables/table.py
> ", line 547, in __init__
>     descr_from_dtype(description)
>   File
> "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/sit
> e-packages/tables-2.2.1.dev-py2.6-macosx-10.6-fat.egg/tables/descript
> ion.py", line 725, in descr_from_dtype
>     for (name, (dtype, pos)) in dtype_.fields.items():
> AttributeError: 'NoneType' object has no attribute 'items'
> Closing remaining open files: test.h5... done
> 
> 
> I think the reason is that for a homogenous array the dtype is simply
> a scalar value so far example for my data array:
> its dtype('int32').  Can someone tell me what I'm doing wrong or is
> this maybe a bug in pytables?
> I would think that such a numpy data type should be supported well in
> pytables.

The problem here is that you are trying to feed an homogeneous array 
into a Table object, which is rather meant for heterogeneous data (i.e. 
the equivalent of numpy structured arrays).  For saving homogeneous 
data, using an Array/CArray/EArray is the way to go.

But I recognize that the error message for your example should be 
clearer.  Could you open a ticket on this so that I can get track of it?

Thanks,

-- 
Francesc Alted

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users

Reply via email to