def rename_with_checks(df, columns, **kwargs):
    """
    Same than df.rename(columns=<columns>, **kwargs) but checks that columns exist before executing.
    """
    missing = set(columns.keys()).difference(set(df.columns))
    if len(missing) > 0:
        raise ValueError("Missing columns: %s" % missing)

    return df.rename(columns=columns, **kwargs)