def set_num_parts(df, max_num_parts):
    """Set number of partitions.

    :param max_num_parts maximum number of partitions
    """
    if df.rdd.getNumPartitions() > max_num_parts:
        df = df.repartition(max_num_parts)
    return df