def eval_table(tbl, expression, vm='python', blen=None, storage=None,
               create='array', vm_kwargs=None, **kwargs):
    """Evaluate `expression` against columns of a table."""

    # setup
    storage = _util.get_storage(storage)
    names, columns = _util.check_table_like(tbl)
    length = len(columns[0])
    if vm_kwargs is None:
        vm_kwargs = dict()

    # setup vm
    if vm == 'numexpr':
        import numexpr
        evaluate = numexpr.evaluate
    elif vm == 'python':
        # noinspection PyUnusedLocal
        def evaluate(expr, local_dict=None, **kw):
            # takes no keyword arguments
            return eval(expr, dict(), local_dict)
    else:
        raise ValueError('expected vm either "numexpr" or "python"')

    # compile expression and get required columns
    variables = _get_expression_variables(expression, vm)
    required_columns = {v: columns[names.index(v)] for v in variables}

    # determine block size for evaluation
    blen = _util.get_blen_table(required_columns, blen=blen)

    # build output
    out = None
    for i in range(0, length, blen):
        j = min(i+blen, length)
        blocals = {v: c[i:j] for v, c in required_columns.items()}
        res = evaluate(expression, local_dict=blocals, **vm_kwargs)
        if out is None:
            out = getattr(storage, create)(res, expectedlen=length, **kwargs)
        else:
            out.append(res)

    return out
def eval_table ( tbl , expression , vm = 'python' , blen = None , storage = None , create = 'array' , vm_kwargs = None , ** kwargs ) : storage = _util . get_storage ( storage ) names , columns = _util . check_table_like ( tbl ) length = len ( columns [ 0 ] ) if vm_kwargs is None : vm_kwargs = dict ( ) if vm == 'numexpr' : import numexpr evaluate = numexpr . evaluate elif vm == 'python' : def evaluate ( expr , local_dict = None , ** kw ) : return eval ( expr , dict ( ) , local_dict ) else : raise ValueError ( 'expected vm either "numexpr" or "python"' ) variables = _get_expression_variables ( expression , vm ) required_columns = { v : columns [ names . index ( v ) ] for v in variables } blen = _util . get_blen_table ( required_columns , blen = blen ) out = None for i in range ( 0 , length , blen ) : j = min ( i + blen , length ) blocals = { v : c [ i : j ] for v , c in required_columns . items ( ) } res = evaluate ( expression , local_dict = blocals , ** vm_kwargs ) if out is None : out = getattr ( storage , create ) ( res , expectedlen = length , ** kwargs ) else : out . append ( res ) return out
Evaluate `expression` against columns of a table.