def _groupby_consecutive(txn, max_delta=pd.Timedelta('<STR_LIT>')):
def vwap(transaction):<EOL><INDENT>if transaction.amount.sum() == <NUM_LIT:0>:<EOL><INDENT>warnings.warn('<STR_LIT>')<EOL>return np.nan<EOL><DEDENT>return (transaction.amount * transaction.price).sum() /transaction.amount.sum()<EOL><DEDENT>out = []<EOL>for sym, t in txn.groupby('<STR_LIT>'):<EOL><INDENT>t = t.sort_index()<EOL>t.index.name = '<STR_LIT>'<EOL>t = t.reset_index()<EOL>t['<STR_LIT>'] = t.amount > <NUM_LIT:0><EOL>t['<STR_LIT>'] = (t.order_sign.shift(<EOL><NUM_LIT:1>) != t.order_sign).astype(int).cumsum()<EOL>t['<STR_LIT>'] = ((t.dt.sub(t.dt.shift(<NUM_LIT:1>))) ><EOL>max_delta).astype(int).cumsum()<EOL>grouped_price = (t.groupby(('<STR_LIT>',<EOL>'<STR_LIT>'))<EOL>.apply(vwap))<EOL>grouped_price.name = '<STR_LIT>'<EOL>grouped_rest = t.groupby(('<STR_LIT>', '<STR_LIT>')).agg({<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': '<STR_LIT>'})<EOL>grouped = grouped_rest.join(grouped_price)<EOL>out.append(grouped)<EOL><DEDENT>out = pd.concat(out)<EOL>out = out.set_index('<STR_LIT>')<EOL>return out<EOL>
Merge transactions of the same direction separated by less than
    max_delta time duration.

    Parameters
    ----------
    transactions : pd.DataFrame
        Prices and amounts of executed round_trips. One row per trade.
        - See full explanation in tears.create_full_tear_sheet

    max_delta : pandas.Timedelta (optional)
        Merge transactions in the same direction separated by less
        than max_delta time duration.


    Returns
    -------
    transactions : pd.DataFrame