MCPcopy Create free account
hub / github.com/dask/dask / repartition

Function repartition

dask/dataframe/dask_expr/_collection.py:5955–5995  ·  view source on GitHub ↗

Repartition dataframe along new divisions Dask.DataFrame objects are partitioned along their index. Often when multiple dataframes interact we need to align these partitionings. The ``repartition`` function constructs a new DataFrame object holding the same data but partitioned on

(df, divisions, force=False)

Source from the content-addressed store, hash-verified

5953
5954
5955def repartition(df, divisions, force=False):
5956 """Repartition dataframe along new divisions
5957
5958 Dask.DataFrame objects are partitioned along their index. Often when
5959 multiple dataframes interact we need to align these partitionings. The
5960 ``repartition`` function constructs a new DataFrame object holding the same
5961 data but partitioned on different values. It does this by performing a
5962 sequence of ``loc`` and ``concat`` calls to split and merge the previous
5963 generation of partitions.
5964
5965 Parameters
5966 ----------
5967
5968 divisions : list
5969 List of partitions to be used
5970 force : bool, default False
5971 Allows the expansion of the existing divisions.
5972 If False then the new divisions lower and upper bounds must be
5973 the same as the old divisions.
5974
5975 Examples
5976 --------
5977
5978 >>> df = df.repartition([0, 5, 10, 20]) # doctest: +SKIP
5979
5980 Also works on Pandas objects
5981
5982 >>> ddf = dd.repartition(df, [0, 5, 10, 20]) # doctest: +SKIP
5983 """
5984 if isinstance(df, FrameBase):
5985 return df.repartition(divisions=divisions, force=force)
5986 elif is_dataframe_like(df) or is_series_like(df):
5987 return new_collection(
5988 FromPandasDivisions(
5989 _BackendData(df),
5990 divisions=divisions,
5991 pyarrow_strings_enabled=pyarrow_strings_enabled(),
5992 )
5993 )
5994 else:
5995 raise NotImplementedError(f"repartition is not implemented for {type(df)}.")
5996
5997
5998def pivot_table(df, index, columns, values, aggfunc="mean"):

Calls 7

new_collectionFunction · 0.90
FromPandasDivisionsClass · 0.90
_BackendDataClass · 0.90
pyarrow_strings_enabledFunction · 0.90
is_dataframe_likeFunction · 0.85
is_series_likeFunction · 0.85
repartitionMethod · 0.45

Tested by 4

test_repartition_noopFunction · 0.72