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

Method shuffle

dask/dataframe/dask_expr/_collection.py:838–948  ·  view source on GitHub ↗

Rearrange DataFrame into new partitions Uses hashing of `on` to map rows to output partitions. After this operation, rows with the same value of `on` will be in the same partition. Parameters ---------- on : str, list of str, or Series, Index, or Dat

(
        self,
        on: str | list | no_default = no_default,  # type: ignore
        ignore_index: bool = False,
        npartitions: int | None = None,
        shuffle_method: str | None = None,
        on_index: bool = False,
        force: bool = False,
        **options,
    )

Source from the content-addressed store, hash-verified

836 return self.partitions[n]
837
838 def shuffle(
839 self,
840 on: str | list | no_default = no_default, # type: ignore
841 ignore_index: bool = False,
842 npartitions: int | None = None,
843 shuffle_method: str | None = None,
844 on_index: bool = False,
845 force: bool = False,
846 **options,
847 ):
848 """Rearrange DataFrame into new partitions
849
850 Uses hashing of `on` to map rows to output partitions. After this
851 operation, rows with the same value of `on` will be in the same
852 partition.
853
854 Parameters
855 ----------
856 on : str, list of str, or Series, Index, or DataFrame
857 Column names to shuffle by.
858 ignore_index : optional
859 Whether to ignore the index. Default is ``False``.
860 npartitions : optional
861 Number of output partitions. The partition count will
862 be preserved by default.
863 shuffle_method : optional
864 Desired shuffle method. Default chosen at optimization time.
865 on_index : bool, default False
866 Whether to shuffle on the index. Mutually exclusive with 'on'.
867 Set this to ``True`` if 'on' is not provided.
868 force : bool, default False
869 This forces the optimizer to keep the shuffle even if the final
870 expression could be further simplified.
871 **options : optional
872 Algorithm-specific options.
873
874 Notes
875 -----
876 This does not preserve a meaningful index/partitioning scheme. This
877 is not deterministic if done in parallel.
878
879 Examples
880 --------
881 >>> df = df.shuffle(df.columns[0]) # doctest: +SKIP
882 """
883 if on is no_default and not on_index: # type: ignore
884 raise TypeError(
885 "Must shuffle on either columns or the index; currently shuffling on "
886 "neither. Pass column(s) to 'on' or set 'on_index' to True."
887 )
888 elif on is not no_default and on_index:
889 raise TypeError(
890 "Cannot shuffle on both columns and the index. Do not pass column(s) "
891 "to 'on' or set 'on_index' to False."
892 )
893
894 # Preserve partition count by default
895 npartitions = npartitions or self.npartitions

Calls 7

is_dask_collectionFunction · 0.90
new_collectionFunction · 0.90
RearrangeByColumnClass · 0.90
get_specified_shuffleFunction · 0.90
anyFunction · 0.85
map_partitionsMethod · 0.45