Hello again, I'm having another problem adding columns. The problem happens
if one of the columns is multidimensional (not sure if that is the correct
term), that is if in instead of having a Float64Col() I have a
Float64Col(n). See below a sample script reproducing the problem. Any
advice?
Armando.
---------
"Modified from
http://pytables.org/svn/pytables/branches/std-2.1/examples/add-column.py"
from tables import *
class Particle(IsDescription):
name = StringCol(16, pos=1) # 16-character String
lati = Int32Col(pos=2) # integer
longi = Int32Col(pos=3) # integer
pressure = Float32Col(pos=4) # float (single-precision)
temperature = Float64Col(2, pos=5) # double (double-precision)
##### CHANGED THIS LINE
# Open a file in "w"rite mode
fileh = openFile("add-column.h5", mode = "w")
# Create a new group
group = fileh.createGroup(fileh.root, "newgroup")
# Create a new table in newgroup group
table = fileh.createTable(group, 'table', Particle, "A table", Filters(1))
# Append several rows
table.append([("Particle: 10", 10, 0, 10*10, [10**2, 1]), ##### CHANGED
THIS LINE
("Particle: 11", 11, -1, 11*11, [11**2, 2]), #####
CHANGED THIS LINE
("Particle: 12", 12, -2, 12*12, [12**2, 3])]) #####
CHANGED THIS LINE
print "Contents of the original table:", fileh.root.newgroup.table[:]
# close the file
fileh.close()
# Open it again in append mode
fileh = openFile("add-column.h5", "a")
group = fileh.root.newgroup
table = group.table
# Get a description of table in dictionary format
descr = table.description._v_colObjects
descr2 = descr.copy()
# Add a column to description
descr2["hot"] = BoolCol(dflt=False)
# Create a new table with the new description
table2 = fileh.createTable(group, 'table2', descr2, "A table", Filters(1))
# Fill the rows of new table with default values
for i in xrange(table.nrows):
table2.row.append()
# Flush the rows to disk
table2.flush()
# Copy the columns of source table to destination
for col in descr:
getattr(table2.cols, col)[:] = getattr(table.cols, col)[:] ##### HERE I
GET AN ERROR -> ValueError: array dimensions are not compatible for copy
# Fill the new column
table2.cols.hot[:] = [ row["temperature"] > 11**2 for row in table ]
# Remove the original table
table.remove()
# Move table2 to table
table2.move('/newgroup','table')
# Print the new table
print "Contents of the table with column added:",
fileh.root.newgroup.table[:]
# Finally, close the file
fileh.close()
------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited
royalty-free distribution of the report engine for externally facing
server and web deployment.
http://p.sf.net/sfu/businessobjects
_______________________________________________
Pytables-users mailing list
Pytables-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pytables-users