Reading a sqlite3.Binary object with numpy.genfromtxt
Question: I have a text file that containes a large string that was originally a binary
blob in an SQL column. I would like to read the data using `numpy.genfromtxt`
and convert the text to a 1D numpy array and then to a binary blob to be
imported later into SQL using the converters parameter:

    
    
           np.genfromtxt(data, delimiter='\t',
                  dtype = [ ("a", 'f8'), ("b", 'U100'), ("c", 'f8') ],
                  converters = {1: lambda x: sqlite3.Binary(
                         np.fromstring(x, dtype='f4', sep=' '))})
    

And the imput file would be something like this:

1.0\t1.0 2.0 3.0\t1.0

However this gives the error message:

    
    
      File "./import_sql.py", line 25, in <module>
        converters = {19: lambda x: sqlite3.Binary(
      File "/usr/lib/python3.4/site-packages/numpy/lib/npyio.py", line 1742, in genfromtxt
        rows = np.array(data, dtype=[('', _) for _ in dtype_flat])
    ValueError: cannot set an array element with a sequence
    

I would like to have genfromtxt return an array where the first and third
columns will contain float values and the second column contains
sqlite3.Binary blob of data with a 1D numpy array.

This does not work so I have read the data into a large string in the output
from genfromtxt and then process it before writing the data to the database.
Is it possible to include a sqlite3.Binary object into a numpy array?


Answer: You just have to switch the type of column `b` from type `'U100'` to `object`,
then it should work.

