Hello, <br><br>I recently had to get data from a mysql database into a recarray. The result was not very long but nontrivial to figure out: <br><br><div style="margin-left: 40px;">def recarray_from_db(db, command):<br>    """ executes a command and turns the results into a numpy recarray (record array)"""<br>
    cursor = db.cursor()<br>    cursor.execute(command)<br>    <br>    column_dtypes = [(col[0], _convert(col[1])) for col in cursor.description]<br>    <br>    return np.fromiter((tuple (row) for row in cursor), dtype=column_dtypes, count = cursor.rowcount)<br>
<br>_type_conversions = {decimal.Decimal : float}<br>
def _convert(type):<br>
    try :<br>
        return _type_conversions[type]<br>
    except:<br>
        return type<br></div><br><br>It uses only the Python database API. Would something like this be a useful addition to numpy (maybe have it take a cursor object instead of a connection object)?<br><br>I also found the following function useful for results with timedate columns, since numpy does not yet have a datetime dtype.<br>
<br><div style="margin-left: 40px;">def time_column(date, column_name):<br>    """ makes a string for calculating a time as (decimal) number of days since a date for a MySQL column. This is because the numpy.datetime datatype is not well developed."""<br>
    return "TIME_TO_SEC(timediff(" + column_name + ",'" +  str(datetime.strptime(date, date_format)) + "'))/(60*60*24) as " + column_name<br>date_format = '%Y-%m-%d'<br><br></div>
<br>Best Regards,<br>John<br>