Table.append() error w/ one column

11 views
Skip to first unread message

Ken Walker

unread,
Nov 26, 2018, 12:03:22 PM11/26/18
to pytables-users
I've been tinkering with Table.append and ran into an error I can't diagnose.
I started with the 'Particle" append example in the documentation here:

The description defines 5 columns and Table.append() works exactly as documented: 
class Particle(tb.IsDescription):
    name        
= tb.StringCol(16, pos=1) # 16-character String
    lati        
= tb.IntCol(pos=2) # integer
    longi      
= tb.IntCol(pos=3) # integer
    pressure    
= tb.Float32Col(pos=4) # float (single-precision)
    temperature
= tb.FloatCol(pos=5) # double (double-precision)

When I modified to only define the 'name' column, I get an error.
The same happens when I only define the 'pressure' column (at pos=1)
Table.append seems to work so long as I have 2 or more columns.
Is this a limitation of the Table.append method?

To verify I can append to a table with 1 column, I used the table.row / append method (similar to tutorial 1).
The following code works:
import tables as tb, numpy as np
class Particle(tb.IsDescription):
    name      
= tb.StringCol(16)   # 16-character String

h5f
= tb.open_file("particle_t1.h5", mode="w", title="Test file")
group1
= h5f.create_group("/", 'detector1', 'Detector1 information')
table1
= h5f.create_table(group1, 'readout1', Particle, "Readout example")
particle
= table1.row
for i in range(3):
    particle
['name']  = 'Particle: %6d' % (i)
    particle
.append()

table1
.flush()

for x in table1.iterrows() :
 
print (x['name'])

h5f
.close()

The following code gives an error when appending to table1:
import tables as tb
class Particle(tb.IsDescription):
    name        
= tb.StringCol(16, pos=1) # 16-character String

h5f  
= tb.open_file('append_t1.h5', mode='w')
group1
= h5f.create_group("/", 'detector1', 'Detector1 information')
table1
= h5f.create_table(group1, 'readout1', Particle, "A table")

# Append several rows in only one call
table1
.append([("Particle:     10"),
               
("Particle:     11"),
               
("Particle:     12")])

for x in table1.iterrows():
 
print (x['name'])

h5f.close()

Am I missing something?
Thanks.

Francesc Alted

unread,
Nov 26, 2018, 12:11:26 PM11/26/18
to Ken Walker, pytable...@googlegroups.com
Hi Ken,

Yes, to create an actual tuple, you missed the comma after the string (e.g. ("Particle:     10",)).  After fixing this in your second example, this is the output I am getting:

b'Particle:     10'

b'Particle:     11'

b'Particle:     12'


Cheers
Francesc

--
You received this message because you are subscribed to the Google Groups "pytables-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pytables-user...@googlegroups.com.
To post to this group, send email to pytable...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Francesc Alted

Ken Walker

unread,
Nov 26, 2018, 1:02:10 PM11/26/18
to pytables-users
That's embarrassing. LOL @ me
Thanks for the quick response.
Reply all
Reply to author
Forward
0 new messages