|
From: Francesc A. <fa...@py...> - 2004-10-09 09:54:48
|
Hi Daehyok,
The ultimate reason for this is that numarray.records.array cannot convert a
list of arrays to a RecArray. See:
In [27]: records.array([[1.,2.]]*3, formats='f8,f8')
Out[27]:
array(
[(1.0, 2.0),
(1.0, 2.0),
(1.0, 2.0)],
formats=['1Float64', '1Float64'],
shape=3,
names=['c1', 'c2'])
That works well. But...
In [28]: records.array([array([1.,2.])]*3, formats='f8,f8')
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
/home/falted/python.nobackup/IM-2004.01.05/<console>
/usr/local/lib/python2.3/site-packages/numarray/records.py in array(buffer, formats, shape, names, byteorder, aligned)
382 if isinstance(buffer[0], num.NumArray) or isinstance(buffer[0], chararray.CharArray):
383 return fromarrays(buffer, formats=formats, shape=shape, names=names,
--> 384 byteorder=byteorder, aligned=aligned)
385 else:
386 return fromrecords(buffer, formats=formats, shape=shape, names=names,
/usr/local/lib/python2.3/site-packages/numarray/records.py in fromarrays(arrayList, formats, names, shape, byteorder, aligned)
183 for i in range(len(arrayList)):
184 try:
--> 185 _array.field(_array._names[i])[:] = arrayList[i]
186 except TypeError: # trap only TypeError to get better messages
187 raise TypeError, "Incorrect format %s, copy unsuccessful." % _array._formats[i]
IndexError: list index out of range
does not work.
Perhaps, this worked with previous versions of numarray, I can't remember.
Anyway, I'll remove the part of manual where I say that Table.append() do
accept lists of numarrays/Numeric/chararray.
Cheers,
Francesc
A Divendres 08 Octubre 2004 23:17, Shin va escriure:
> While filling up a table, I met a strange error message.
> When the appended program is tried with version 0.8.1,
> only the second trial to use a list of arrays raises an ValueError.
> But, the manual says I can use a list of numarrays to append multi-rows.
> What did I miss? Or, a bug? Thanks.
>
> >>>>>>>>>>>>>>> test3.py <<<<<<<<<<<<<<<<<<
>
> #!/usr/bin/env python
>
> from numarray import *
> from tables import *
>
> # By using a list of lists.
> class Cols(IsDescription):
> V1 = FloatCol()
> V2 = FloatCol()
>
> f = openFile("test.hd5", "w")
> tab = f.createTable("/","Data",Cols,"Data")
>
> d = []
> for i in range(10):
> d = d + [[1.0,1.0]]
>
> tab.append(d)
> f.close()
>
> # By using a list of arrays.
>
> f = openFile("test.hd5", "w")
> tab = f.createTable("/","Data",Cols,"Data")
>
> d = []
> for i in range(10):
> d = d + [array([1.0,1.0])]
>
> tab.append(d)
> f.close()
>
> >>>>>>>>> Here is the error message caught in ipython <<<<<<
>
> In [1]: execfile("test3.py")
> ---------------------------------------------------------------------------
> ValueError Traceback (most recent call
> last)
>
> /home/sdhyok/catchlab/catchlab/catchlab/pkg/rhessys/test/<console>
>
> /home/sdhyok/catchlab/catchlab/catchlab/pkg/rhessys/test/test3.py
> 24 for i in range(10):
> 25 d = d + [array([1.0,1.0])]
> 26
> ---> 27 tab.append(d)
> tab = /Data (Table(0,)) 'Data'
> description := {
> ...pe=1, dflt=0.0, pos=None) }
> byteorder := little, global append = undefined, d = [array([ 1.,
> 1.]), array([ 1., 1.]), array([ 1., 1.]), array([ 1., 1.]), array([
> 1., 1.]), array([ 1., 1.]), array([ 1., 1.]), array([ 1., 1.]),
> array([ 1., 1.]), array([ 1., 1.])]
> 28 f.close()
>
> /usr/lib/python2.3/site-packages/tables/Table.py in append(self=/Data
> (Table(0,)) 'Data'
> description := {
> ...pe=1, dflt=0.0, pos=None) }
> byteorder := little, rows=[array([ 1., 1.]), array([ 1., 1.]),
> array([ 1., 1.]), array([ 1., 1.]), array([ 1., 1.]), array([ 1.,
> 1.]), array([ 1., 1.]), array([ 1., 1.]), array([ 1., 1.]), array([
> 1., 1.])])
> 588 except:
> 589 (type, value, traceback) = sys.exc_info()
> --> 590 raise ValueError, \
> global ValueError = undefined, global str = undefined, self =
> /Data (Table(0,)) 'Data'
> description := {
> ...pe=1, dflt=0.0, pos=None) }
> byteorder := little, value = <exceptions.IndexError instance>
> 591 "rows parameter cannot be converted into a recarray object
> compliant with table '%s'. The error was: <%s>" % (str(self), value)
> 592 lenrows = recarray.shape[0]
>
> ValueError: rows parameter cannot be converted into a recarray object
> compliant with table '/Data (Table(0,)) 'Data''. The error was: <list
> index out of range>
>
--
Francesc Alted
|