python/ray/data/dataset.py
def random_shuffle(
        self,
        *,
        seed: Optional[int] = None,
        num_blocks: Optional[int] = None,
    ) -> "Dataset[T]":
        """Randomly shuffle the elements of this dataset.

        This is a blocking operation similar to repartition().

        Examples:
            >>> import ray
            >>> ds = ray.data.range(100) # doctest: +SKIP
            >>> # Shuffle this dataset randomly.
            >>> ds.random_shuffle() # doctest: +SKIP
            >>> # Shuffle this dataset with a fixed random seed.
            >>> ds.random_shuffle(seed=12345) # doctest: +SKIP

        Time complexity: O(dataset size / parallelism)

        Args:
            seed: Fix the random seed to use, otherwise one will be chosen
                based on system randomness.
            num_blocks: The number of output blocks after the shuffle, or None
                to retain the number of blocks.

        Returns:
            The shuffled dataset.
        """

        def do_shuffle(block_list, clear_input_blocks: bool, block_udf, remote_args):
            num_blocks = block_list.executed_num_blocks()  # Blocking.
            if num_blocks == 0:
                return block_list, {}
            if clear_input_blocks:
                blocks = block_list.copy()
                block_list.clear()
            else:
                blocks = block_list
            random_shuffle_op = ShufflePartitionOp(
                block_udf, random_shuffle=True, random_seed=seed
            )
            return random_shuffle_op.execute(
                blocks,
                num_blocks,
                clear_input_blocks,
                map_ray_remote_args=remote_args,
                reduce_ray_remote_args=remote_args,
            )

        plan = self._plan.with_stage(
            AllToAllStage(
                "random_shuffle", num_blocks, do_shuffle, supports_block_udf=True
            )
        )
        return Dataset(plan, self._epoch, self._lazy)
Randomly shuffle the elements of this dataset.

        This is a blocking operation similar to repartition().

        Examples:
            >>> import ray
            >>> ds = ray.data.range(100) # doctest: +SKIP
            >>> # Shuffle this dataset randomly.
            >>> ds.random_shuffle() # doctest: +SKIP
            >>> # Shuffle this dataset with a fixed random seed.
            >>> ds.random_shuffle(seed=12345) # doctest: +SKIP

        Time complexity: O(dataset size / parallelism)

        Args:
            seed: Fix the random seed to use, otherwise one will be chosen
                based on system randomness.
            num_blocks: The number of output blocks after the shuffle, or None
                to retain the number of blocks.

        Returns:
            The shuffled dataset.
        
Randomly shuffle the elements of this dataset.
This is a blocking operation similar to repartition().
Randomly shuffle the elements of this dataset . This is a blocking operation similar to repartition () .
def random_shuffle(
        self,
        *,
        seed: Optional[int] = None,
        num_blocks: Optional[int] = None,
    ) -> "Dataset[T]":
        def do_shuffle(block_list, clear_input_blocks: bool, block_udf, remote_args):
            num_blocks = block_list.executed_num_blocks()  
            if num_blocks == 0:
                return block_list, {}
            if clear_input_blocks:
                blocks = block_list.copy()
                block_list.clear()
            else:
                blocks = block_list
            random_shuffle_op = ShufflePartitionOp(
                block_udf, random_shuffle=True, random_seed=seed
            )
            return random_shuffle_op.execute(
                blocks,
                num_blocks,
                clear_input_blocks,
                map_ray_remote_args=remote_args,
                reduce_ray_remote_args=remote_args,
            )
        plan = self._plan.with_stage(
            AllToAllStage(
                "random_shuffle", num_blocks, do_shuffle, supports_block_udf=True
            )
        )
        return Dataset(plan, self._epoch, self._lazy)
def random_shuffle ( self , * , seed : Optional [ int ] = None , num_blocks : Optional [ int ] = None , ) -> "Dataset[T]" : def do_shuffle ( block_list , clear_input_blocks : bool , block_udf , remote_args ) : num_blocks = block_list . executed_num_blocks ( ) if num_blocks == 0 : return block_list , { } if clear_input_blocks : blocks = block_list . copy ( ) block_list . clear ( ) else : blocks = block_list random_shuffle_op = ShufflePartitionOp ( block_udf , random_shuffle = True , random_seed = seed ) return random_shuffle_op . execute ( blocks , num_blocks , clear_input_blocks , map_ray_remote_args = remote_args , reduce_ray_remote_args = remote_args , ) plan = self . _plan . with_stage ( AllToAllStage ( "random_shuffle" , num_blocks , do_shuffle , supports_block_udf = True ) ) return Dataset ( plan , self . _epoch , self . _lazy )
Randomly shuffle the elements of this dataset.
Randomly shuffle the elements of this dataset .
"""Randomly shuffle the elements of this dataset.

        This is a blocking operation similar to repartition().

        Examples:
            >>> import ray
            >>> ds = ray.data.range(100) # doctest: +SKIP
            >>> # Shuffle this dataset randomly.
            >>> ds.random_shuffle() # doctest: +SKIP
            >>> # Shuffle this dataset with a fixed random seed.
            >>> ds.random_shuffle(seed=12345) # doctest: +SKIP

        Time complexity: O(dataset size / parallelism)

        Args:
            seed: Fix the random seed to use, otherwise one will be chosen
                based on system randomness.
            num_blocks: The number of output blocks after the shuffle, or None
                to retain the number of blocks.

        Returns:
            The shuffled dataset.
        """ # Blocking.
The shuffled dataset.
The shuffled dataset .
self
seed
Optional[int]
Fix the random seed to use, otherwise one will be chosen
based on system randomness.
Fix the random seed to use otherwise one will be chosen based on system randomness .
num_blocks
Optional[int]
The number of output blocks after the shuffle, or None
to retain the number of blocks.
The number of output blocks after the shuffle or None to retain the number of blocks .
examples
>>> import ray
>>> ds = ray.data.range(100) # doctest: +SKIP
>>> # Shuffle this dataset randomly.
>>> ds.random_shuffle() # doctest: +SKIP
>>> # Shuffle this dataset with a fixed random seed.
>>> ds.random_shuffle # doctest: +SKIP
>>> import ray >>> ds = ray . data . range ( 100 ) # doctest : + SKIP >>> # Shuffle this dataset randomly . >>> ds . random_shuffle () # doctest : + SKIP >>> # Shuffle this dataset with a fixed random seed . >>> ds . random_shuffle # doctest : + SKIP