2

I have stock tick data in csv files and for the life of me I cannot figure out why bulk inserts are not working. I have created recarray called insert_records with the following types:

  [('id', 'O'), ('dt', '<i8'), ('adj_dt', '<i8'), ('currency', 'O'), ('close', '<f8'), ('open', '<f8'), ('high', '<f8'), ('low', '<f8'), ('volume', '<f8')]

I have created a table with columns:

OHLCTableDescription = {'id': tables.StringCol(10),
                       'dt': tables.Int64Col(),
                       'adj_dt': tables.Int64Col(),
                       'currency': tables.StringCol(5),
                       'open': tables.Float64Col(dflt=np.NaN),
                       'high': tables.Float64Col(dflt=np.NaN),
                       'low': tables.Float64Col(dflt=np.NaN),
                       'close': tables.Float64Col(dflt=np.NaN),
                       "volume": tables.Float64Col(dflt=np.NaN)}   

this works:

 for row in insert_records:
     current_row = table.row
     dtype = insert_records.dtype.names
     for j in range(len(dtype)):
         current_row[dtype[j]] = row[j]
         current_row.append()

this does not:

table.append(insert_records)

I get this error

 ValueError("rows parameter cannot be converted into a recarray object compliant with table '/TD/date_20130102 (Table(0,), shuffle, zlib(9)) '20130102''. The error was: <Cannot change data-type for object array.>",)
rows parameter cannot be converted into a recarray object compliant with table '/TD/date_20130102 (Table(0,), shuffle, zlib(9)) '20130102''. The error was: <Cannot change data-type for object array.>

What does this error refer to?

4

1 回答 1

0

python 对象不能用于附加到 pytables。pytables 需要精确的recarray 数据类型。

如果 dtype 更改,这将附加。

 dtype[0] = "|S14"
于 2013-12-05T21:52:55.780 回答