def insert_column(rec, N, col, name=None, format=None):
    col = np.array(col)

    # get name and format parameter from column if not provided
    if name is None:
        if col.dtype.names is not None:
            name = col.dtype.names
        else:
            raise ValueError("Must provide a name for the column")
    if format is None:
        format = col.dtype.str

    # insert the new column (name, format) to the table dtypes
    dtd = rec.dtype.descr
    dtd.insert(N, (name, format))

    # create the new table with an additional column
    new_rec = np.empty(rec.shape, dtd)

    # fill in the old columns
    for n in rec.dtype.names:
        new_rec[n] = rec[n]
    # and the new column
    new_rec[name] = col.astype(format)

    return np.atleast_1d(np.rec.array(new_rec))
Get the version for this extension.
dataset/ETHPy150Open jjhelmus/nmrglue/nmrglue/fileio/table.py/insert_column--crossover with--dataset/ETHPy150Open jzempel/flask-exceptional/flask_exceptional.py/Exceptional.__version__