@dispatch(Expr, Mapping)
def compute(expr, d, return_type=no_default, **kwargs):
    """Compute expression against data sources.

    Parameters
    ----------
    expr : str
        blaze expression
    d: resource
        data source to compute expression on
    return_type : {'native', 'core', type}, optional
        Type to return data as. Defaults to 'native' but will be changed
        to 'core' in version 0.11.  'core' forces the computation into a core type.
        'native' returns the result as is from the respective backend's `post_compute`.
        If a type is passed, it will odo the result into the type before returning.

    >>> t = symbol('t', 'var * {name: string, balance: int}')
    >>> deadbeats = t[t['balance'] < 0]['name']

    >>> data = [['Alice', 100], ['Bob', -50], ['Charlie', -20]]
    >>> list(compute(deadbeats, {t: data}))
    ['Bob', 'Charlie']
    """
    _reset_leaves()
    optimize_ = kwargs.get('optimize', optimize)
    pre_compute_ = kwargs.get('pre_compute', pre_compute)
    post_compute_ = kwargs.get('post_compute', post_compute)
    expr2, d2 = swap_resources_into_scope(expr, d)
    if pre_compute_:
        d3 = dict(
            (e, pre_compute_(e, dat, **kwargs))
            for e, dat in d2.items()
            if e in expr2
        )
    else:
        d3 = d2

    if optimize_:
        try:
            expr3 = optimize_(expr2, *[v for e, v in d3.items() if e in expr2])
            _d = dict(zip(expr2._leaves(), expr3._leaves()))
            d4 = dict((e._subs(_d), d) for e, d in d3.items())
        except __HOLE__:
            expr3 = expr2
            d4 = d3
    else:
        expr3 = expr2
        d4 = d3

    result = top_then_bottom_then_top_again_etc(expr3, d4, **kwargs)
    if post_compute_:
        result = post_compute_(expr3, result, scope=d4)

    # return the backend's native response
    if return_type is no_default:
        msg = ("The default behavior of compute will change in version >= 0.11"
               " where the `return_type` parameter will default to 'core'.")
        warnings.warn(msg, DeprecationWarning)
    # return result as a core type
    # (python type, pandas Series/DataFrame, numpy array)
    elif return_type == 'core':
        result = coerce_core(result, expr.dshape)
    # user specified type
    elif isinstance(return_type, type):
        result = into(return_type, result)
    elif return_type != 'native':
        raise ValueError(
            "Invalid return_type passed to compute: {}".format(return_type),
        )

    return result
dataset/ETHPy150Open blaze/blaze/blaze/compute/core.py/compute