def build_expressions(verb):
    """
    Build expressions for helper verbs

    Parameters
    ----------
    verb : verb
        A verb with a *functions* attribute.

    Returns
    -------
    out : tuple
        (List of Expressions, New columns). The expressions and the
        new columns in which the results of those expressions will
        be stored. Even when a result will stored in a column with
        an existing label, that column is still considered new,
        i.e An expression ``x='x+1'``, will create a new_column `x`
        to replace an old column `x`.
    """
    def partial(func, col, *args, **kwargs):
        """
        Make a function that acts on a column in a dataframe

        Parameters
        ----------
        func : callable
            Function
        col : str
            Column
        args : tuple
            Arguments to pass to func
        kwargs : dict
            Keyword arguments to func

        Results
        -------
        new_func : callable
            Function that takes a dataframe, and calls the
            original function on a column in the dataframe.
        """
        def new_func(gdf):
            return func(gdf[col], *args, **kwargs)

        return new_func

    def make_statement(func, col):
        """
        A statement of function called on a column in a dataframe

        Parameters
        ----------
        func : str or callable
            Function to call on a dataframe column
        col : str
            Column
        """
        if isinstance(func, str):
            expr = '{}({})'.format(func, col)
        elif callable(func):
            expr = partial(func, col, *verb.args, **verb.kwargs)
        else:
            raise TypeError("{} is not a function".format(func))
        return expr

    def func_name(func):
        """
        Return name of a function.

        If the function is `np.sin`, we return `sin`.
        """
        if isinstance(func, str):
            return func

        try:
            return func.__name__
        except AttributeError:
            return ''

    # Generate function names. They act as identifiers (postfixed
    # to the original columns) in the new_column names.
    if isinstance(verb.functions, (tuple, list)):
        names = (func_name(func) for func in verb.functions)
        names_and_functions = zip(names, verb.functions)
    else:
        names_and_functions = verb.functions.items()

    # Create statements for the expressions
    # and postfix identifiers
    columns = Selector.get(verb)  # columns to act on
    postfixes = []
    stmts = []
    for name, func in names_and_functions:
        postfixes.append(name)
        for col in columns:
            stmts.append(make_statement(func, col))

    if not stmts:
        stmts = columns

    # Names of the new columns
    # e.g col1_mean, col2_mean, col1_std, col2_std
    add_postfix = (isinstance(verb.functions, dict) or
                   len(verb.functions) > 1)
    if add_postfix:
        fmt = '{}_{}'.format
        new_columns = [fmt(c, p) for p in postfixes for c in columns]
    else:
        new_columns = columns

    expressions = [Expression(stmt, col)
                   for stmt, col in zip(stmts, new_columns)]
    return expressions, new_columns
def build_expressions ( verb ) : def partial ( func , col , * args , ** kwargs ) : def new_func ( gdf ) : return func ( gdf [ col ] , * args , ** kwargs ) return new_func def make_statement ( func , col ) : if isinstance ( func , str ) : expr = '{}({})' . format ( func , col ) elif callable ( func ) : expr = partial ( func , col , * verb . args , ** verb . kwargs ) else : raise TypeError ( "{} is not a function" . format ( func ) ) return expr def func_name ( func ) : if isinstance ( func , str ) : return func try : return func . __name__ except AttributeError : return '' if isinstance ( verb . functions , ( tuple , list ) ) : names = ( func_name ( func ) for func in verb . functions ) names_and_functions = zip ( names , verb . functions ) else : names_and_functions = verb . functions . items ( ) columns = Selector . get ( verb ) postfixes = [ ] stmts = [ ] for name , func in names_and_functions : postfixes . append ( name ) for col in columns : stmts . append ( make_statement ( func , col ) ) if not stmts : stmts = columns add_postfix = ( isinstance ( verb . functions , dict ) or len ( verb . functions ) > 1 ) if add_postfix : fmt = '{}_{}' . format new_columns = [ fmt ( c , p ) for p in postfixes for c in columns ] else : new_columns = columns expressions = [ Expression ( stmt , col ) for stmt , col in zip ( stmts , new_columns ) ] return expressions , new_columns
Build expressions for helper verbs

    Parameters
    ----------
    verb : verb
        A verb with a *functions* attribute.

    Returns
    -------
    out : tuple
        (List of Expressions, New columns). The expressions and the
        new columns in which the results of those expressions will
        be stored. Even when a result will stored in a column with
        an existing label, that column is still considered new,
        i.e An expression ``x='x+1'``, will create a new_column `x`
        to replace an old column `x`.