loadstep_row_data = loadsteps_table.row
for i in range(1, num_loadsteps_to_append):
loadstep_row_data ['loadStepID'] = i+1
loadstep_row_data ['profileID'] = i+1
loadstep_row_data ['file'] = i
loadstep_row_data.append()
I get the following error in running the above code. What to do to avoid the error?
loadstep_row_data.append()
File "tables\tableextension.pyx", line 1319, in tables.tableextension.Row.append
tables.exceptions.HDF5ExtError: You cannot append rows to a non-chunked table.
I tried in Python 3.10.7
The error message is slightly misleading. What you need are resizable tables (aka HDF5 datasets). This allows you to add data later. Tables are resizable (by default) when you create a table with PyTables. However, this is not the default behavior for other packages and programs. How was your H5 file originally created? If not by PyTables, it may not be resizable. All is not lost if your table is not resizable. You can cope the data to a new file with tables that are resizable. (Yes, more work, but not rocket science.)
Examples below demonstrate the different behaviors. They may help you diagnose your situation. The second example replicates your error message.
Example 1: Use PyTables to create Table and append data
This example creates the file with PyTables, then successfully adds 5 rows of data using your row-by-row method. It also shows how to add all 5 rows of data with 1
Table.append()call. This is generally much faster than adding row-by-row.Step 1: Create File and Table with 5 rows of data:
Step 2a: Reopen File; add 5 rows of data to table (add row-by-row):
Step 2b: Continues, adding 5 more rows of data to table (all 5 rows at once):
Example 2: Use h5py to create Dataset/Table, and PyTables to append the data
This example creates the file with h5py. It the reopens the file with PyTables and fails when trying to add 5 rows of data using your row-by-row method. h5py does NOT create reizable datasets by default. It will work if you include this parameter
maxshape=(None,)when creating the dataset.Step 1: Create File and Dataset (Table) with 5 rows of data:
Step 2: Reopen File (with tables); add 5 rows of data to table (gives error):