def join_tables(left, right, key_left, key_right,
                cols_right=None):
    """Perform a join of two tables.

    Parameters
    ----------
    left : `~astropy.Table`
        Left table for join.

    right : `~astropy.Table`
        Right table for join.

    key_left : str
        Key used to match elements from ``left`` table.

    key_right : str
        Key used to match elements from ``right`` table.

    cols_right : list    
        Subset of columns from ``right`` table that will be appended
        to joined table.

    """
    right = right.copy()

    if cols_right is None:
        cols_right = right.colnames
    else:
        cols_right = [c for c in cols_right if c in right.colnames]

    if key_left != key_right:
        right[key_right].name = key_left

    if key_left not in cols_right:
        cols_right += [key_left]

    out = join(left, right[cols_right], keys=key_left,
               join_type='left')

    for col in out.colnames:
        if out[col].dtype.kind in ['S', 'U']:
            out[col].fill_value = ''
        elif out[col].dtype.kind in ['i']:
            out[col].fill_value = 0
        else:
            out[col].fill_value = np.nan

    return out.filled()
Perform a join of two tables.

    Parameters
    ----------
    left : `~astropy.Table`
        Left table for join.

    right : `~astropy.Table`
        Right table for join.

    key_left : str
        Key used to match elements from ``left`` table.

    key_right : str
        Key used to match elements from ``right`` table.

    cols_right : list    
        Subset of columns from ``right`` table that will be appended
        to joined table.