|
From: Stefan K. <pon...@ya...> - 2005-10-24 15:59:28
|
Hi,
If I run this simple loop, I get the output I expect..
table = fp.root.table_0
for row in table:
print row
but when I call row.append(), the output changes and looks corrupted..
table = fp.root.table_0
for row in table:
print row
row.append()
Perhaps I am misunderstanding how row.append works. I want to iterate
over the data a row at a time, set some values in row and have those
values written back.
Here is the output when it's ok ( not calling append ) and then when I
do..
python tmp.py
(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)
(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)
(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0)
(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0)
(4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0)
(5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0)
(6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0)
(7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0)
(8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0)
(9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0)
python tmp.py
(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)
(0.0, 0.0, 5.1949684891682224e-76, 3.2962254796880672e-260, 0.0,
1.28271820187416\
2e+45, -5.4060993840027115e-39, 0.0, 0.0, 0.0)
(0.0, 0.0, 0.0, 0.0, 2.6593181061630576e-293, -2.5144912217698657e-40,
0.0, 0.0, \
0.0, 0.0)
(0.0, 0.0, 0.0, -1.2835448071228927e-247, 1.149435495237775e-260, 0.0,
0.0, 0.0, \
1.4939062567974614e-309, 1.1862805280863329e-306)
(nan, 6.5191367783158677e+91, 1.6975966327722179e-313, 0.0,
1.8849466386307898e-2\
60, 0.0, 2.1219957904712067e-314, 1.9097962134497552e-313,
1.8849900568353108e-26\
0, 4.9406564584124654e-324)
(2.1219957904712067e-314, 1.9097962150307652e-313,
1.8850955010462896e-260, 0.0, \
2.1219957904712067e-314, 1.9097962166117753e-313,
1.8851389192508103e-260, 0.0, 2\
.1219957904712067e-314, 1.9097962181927854e-313)
(1.8852071478579149e-260, 4.2439915829186759e-314,
4.9406564584124654e-324, 1.909\
7962197737954e-313, 1.8853249972701853e-260, 0.0, 0.0, 0.0, 0.0, 0.0)
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
(0.0, 0.0, 0.0, 0.0, 0.0, 2.1219957909652723e-314,
7.644680467577401e-270, 0.0, 4\
.9406564584124654e-324, 0.0)
thanks!
Stefan
__________________________________
Yahoo! FareChase: Search multiple travel sites in one click.
http://farechase.yahoo.com
|
|
From: Francesc A. <fa...@ca...> - 2005-10-25 19:09:13
|
Hi Stefan,
El dl 24 de 10 del 2005 a les 08:59 -0700, en/na Stefan Kuzminski va
escriure:
> If I run this simple loop, I get the output I expect..
>=20
> table =3D fp.root.table_0
> for row in table:
> print row
>=20
> but when I call row.append(), the output changes and looks corrupted..
>=20
> table =3D fp.root.table_0
> for row in table:
> print row
> row.append()
Yes, the ability to modify tables in the middle of iterators was not
implemented yet. I've catched situations where the user tries to do
something like:
for row in table:
row['somefield'] =3D 2
by issuing the next exception:
File "test-append.py", line 42, in read_junk
row['lati'] =3D 2
File "TableExtension.pyx", line 1123, in
TableExtension.Row.__setitem__
NotImplementedError: You cannot set Row fields when in middle of a table
iterator. Use Table.modifyRows() or Table.modifyColumns() instead.
but forgot about append(). Now, I've catched this as well and a similar
exception will be raised:
for row in table:
row.append()
File "test-append.py", line 43, in read_junk
row.append()
File "TableExtension.pyx", line 1038, in TableExtension.Row.append
NotImplementedError: You cannot append rows when in middle of a table
iterator.
Anyway, if what you want is modify columns on an existing table, you can
use something like:
for nrow in xrange(tt.nrows):
row =3D tt[nrow:nrow+1]
row.field('lati')[0] =3D 2
row.field('pressure')[0] =3D nrow
tt.modifyRows(nrow,rows=3Drow)
I'm working implementing a variant of this:
for row in tt:
row['lati'] =3D 2
row['pressure'] =3D row.nrow()
row.modify()
which looks prettier to my eyes. In addition it's much faster (up to 20x
than the former version).
A preliminary version of this later implementation is already in the
PyTables repository and most probably will be included in PyTables 1.2
(provided that I've time to add the test units and documenting it).
If this is what you want, you can have a try at the nigthly tarball that
will be automatically made this night around 0:05 UTC at:
http://www.carabos.com/downloads/pytables/snapshots/
Cheers,
--=20
>0,0< Francesc Altet http://www.carabos.com/
V V C=E1rabos Coop. V. Enjoy Data
"-"
|