Here is more detail on the error (*TypeError: invalid type for ``rating``
column: <type 'int'>*
) I get. Thanks for your help:
##################################
dcw$ python test1-insert.py
movie3.h5 (File) ''
Last modif.: 'Sat May 10 14:25:08 2008'
Object Tree:
/ (RootGroup) ''
/ratings (Table(7L,)) ''
/ratings (Table(7L,)) '' Description([('date', '1i4'), ('movie', '1i4'),
('rating', '1i1'), ('user', '1i4')])
(0, 0, 0, 0)
(0, 17770, 0, 0)
(0, 17770, 2, 2031561)
(0, 0, 0, 0)
(0, 1, 0, 0)
(0, 1, 2, 0)
(0, 3, 3, 0)
17770
Traceback (most recent call last):
File "test1-insert.py", line 16, in ?
row['rating'] = r[1]
File "TableExtension.pyx", line 1301, in TableExtension.Row.__setitem__
*TypeError: invalid type for ``rating`` column: <type 'int'>
*Closing remaining opened files... movie3.h5... done.
#################################
dcw$ <[EMAIL PROTECTED]:~/netflix/data/bin$> cat test1-insert.py
import tables, datetime
h5f = tables.openFile('movie3.h5', 'a')
tbl = h5f.root.ratings
print h5f, tbl, tbl.description
for n in tbl.iterrows():
print n
row = tbl.row
r = [2031561, 2, datetime.date(2003, 12, 29), 17770]
row['date'] = r[2]
print r[3]
row['rating'] = r[1]
row['user'] = r[0]
row['movie'] = r[3]
row.append()
tbl.flush()
##################################
#This works in through ipython
In [15]: tbl.flush
Out[15]:
<bound method Table.flush of /ratings (Table(4L,)) ''
description := {
"date": TimeCol(dflt=0, shape=1, itemsize=4, pos=0, indexed=False),
"movie": Col(dtype='Int32', shape=1, dflt=0, pos=1, indexed=False),
"rating": Col(dtype='Int8', shape=1, dflt=0, pos=2, indexed=False),
"user": Col(dtype='Int32', shape=1, dflt=0, pos=3, indexed=False)}
byteorder := little>
In [27]: i = 3
In [28]: row = tbl.row
In [29]: row['movie'] = i
In [30]: row['rating'] = i
In [31]: row.append()
In [32]: tbl.flush()
In [34]: for n in tbl.iterrows():
....: print n
....:
....:
(0, 0, 0, 0)
(0, 17770, 0, 0)
(0, 17770, 2, 2031561)
(0, 0, 0, 0)
(0, 1, 0, 0)
(0, 1, 2, 0)
(0, 3, 3, 0)
In [35]:
On 5/10/08, David Wilson <[EMAIL PROTECTED]> wrote:
> This is my first post. Thanks for your help.
>
> I am having a weird problem with my first attempt to use PyTables.
>
> In ipython, this works:
>
> import tables
> h5f = tables.open...
> tbl = h5f.root.ratings
> row in tbl.row
> row[column] = 3
> row.append()
>
> ...but if I run the same code from a file ("python foo.py"). I get an
> error. Something like:
> type int not allowed for column in row.__setitem__
>
> Let me know if this jumps out at you (can I use the normal python
> interperetor) does the type get messed up?
>
> I'll post the actual code later today. Thanks for your help!
>
> Dave
>
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference
Don't miss this year's exciting event. There's still time to save $100.
Use priority code J8TL2D2.
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users