def repartition_npartitions(df, npartitions):
    """ Repartition dataframe to a smaller number of partitions """
    npartitions = min(npartitions, df.npartitions)
    k = int(math.ceil(df.npartitions / npartitions))
    divisions = df.divisions[::k]
    if len(divisions) <= npartitions:
        divisions = divisions + (df.divisions[-1],)
    return df.repartition(divisions=divisions)
dataset/ETHPy150Open dask/dask/dask/dataframe/core.py/repartition_npartitions/original