#NEWLINE# def column_map( tables , columns ) : #NEWLINE# #INDENT# '\n    Take a list of tables and a list of column names and resolve which\n    columns come from which table.\n\n    Parameters\n    ----------\n    tables : sequence of _DataFrameWrapper or _TableFuncWrapper\n        Could also be sequence of modified pandas.DataFrames, the important\n        thing is that they have ``.name`` and ``.columns`` attributes.\n    columns : sequence of str\n        The column names of interest.\n\n    Returns\n    -------\n    col_map : dict\n        Maps table names to lists of column names.\n\n    ' #NEWLINE# if ( not columns ) : #NEWLINE# #INDENT# return { t . name : None for t in tables } #NEWLINE# #UNINDENT# columns = set ( columns ) #NEWLINE# colmap = { t . name : list ( set ( t . columns ) . intersection ( columns ) ) for t in tables } #NEWLINE# foundcols = tz . reduce ( ( lambda x , y : x . union ( y ) ) , ( set ( v ) for v in colmap . values ( ) ) ) #NEWLINE# if ( foundcols != columns ) : #NEWLINE# #INDENT# raise RuntimeError ( 'Not all required columns were found. Missing: {}' . format ( list ( ( columns - foundcols ) ) ) ) #NEWLINE# #UNINDENT# return colmap