Read in Strings to vtkTableNode?

Hello,

Whenever I try to use the slicer.util.updateTableFromArray() function to import an array with a string value - say “DeviceID” - I get the error “ValueError: could not convert string to float: ‘DeviceID’”

Numerical arrays work just fine but string arrays, object arrays, or anything that isn’t exclusively numbers fails. If I pass an array of strings that are numbers - for instance np.array([[‘0’, ‘0’, ‘0’]])which could be seen as the equivalent of np.zeros((1,3)).astype(str) - the table reads it in but still has columns with Data type set to float when examined in Slicer’s Table module.

Is there a better way to import string or mixed tables through code?

slicer.util.updateTableFromArray() only works for numeric types (as VTK only offers array mapping for these types). You can set string elements one by one:

column = tableNode.GetTable().GetColumn(0)

column.InsertNextValue("asdf")
column.InsertNextValue("zxcv")
column.InsertNextValue("qwerty")

tableNode.GetTable().Modified()