Repository: ray-project/ray
File: python/ray/data/dataset.py (Python)

Code before:
                except for the last one, will have exactly ``target_num_rows_per_block`` rows.
                If ``False``, ``repartition`` is more relaxed and may produce blocks smaller
                than ``target_num_rows_per_block`` without stitching them together.
                This parameter is only used with ``target_num_rows_per_block``.
                Defaults to ``False``.
            shuffle: Whether to perform a distributed shuffle during the
                repartition. When shuffle is enabled, each output block
                contains a subset of data rows from each input block, which
                requires all-to-all data movement. When shuffle is disabled,
                output blocks are created from adjacent input blocks,
                minimizing data movement.
            keys: List of key columns repartitioning will use to determine which
                partition will row belong to after repartitioning (by applying
                hash-partitioning algorithm to the whole dataset). Note that, this
                config is only relevant when `DataContext.use_hash_based_shuffle`
                is set to True.
            sort: Whether the blocks should be sorted after repartitioning. Note,
                that by default blocks will be sorted in the ascending order.

        Note that you must set either `num_blocks` or `target_num_rows_per_block`
        but not both.
        Additionally note that this operation materializes the entire dataset in memory
        when you set shuffle to True.

        Returns:
            The repartitioned :class:`Dataset`.
        """  # noqa: E501

        if target_num_rows_per_block is not None:
            if keys is not None:
                warnings.warn(
                    "`keys` is ignored when `target_num_rows_per_block` is set."
                )
            if sort is not False:
                warnings.warn(
                    "`sort` is ignored when `target_num_rows_per_block` is set."
                )
            if shuffle:
                warnings.warn(
                    "`shuffle` is ignored when `target_num_rows_per_block` is set."
                )
        else:
            if strict:
                # strict is used in row-based repartition only
                warnings.warn(
                    "`strict` is ignored when `target_num_rows_per_block` is not set. "
                    "Use `target_num_rows_per_block` instead of `num_blocks` to enable `strict` mode."
                )

        if (num_blocks is None) and (target_num_rows_per_block is None):
            raise ValueError(

Review comment (suggestion):
Might be better to say that will only produce at most 1 block that is < target_num_rows_per_block per input block if strict is false.

Code after:
            >>> ds = ray.data.range(100).repartition(10).materialize()
            >>> ds.num_blocks()
            10

        Time complexity: O(dataset size / parallelism)

        Args:
            num_blocks: Number of blocks after repartitioning.
            target_num_rows_per_block: [Experimental] The target number of rows per block to
                repartition. Performs streaming repartitioning of the dataset (no shuffling).
                Note that either `num_blocks` or
                `target_num_rows_per_block` must be set, but not both. When
                `target_num_rows_per_block` is set, it only repartitions
                :class:`Dataset` :ref:`blocks <dataset_concept>` that are larger than
                `target_num_rows_per_block`. Note that the system will internally
                figure out the number of rows per :ref:`blocks <dataset_concept>` for
                optimal execution, based on the `target_num_rows_per_block`. This is
                the current behavior because of the implementation and may change in
                the future.
            strict: If ``True``, ``repartition`` guarantees that all output blocks,
                except for the last one, will have exactly ``target_num_rows_per_block`` rows.
                If ``False``, ``repartition`` uses best-effort bundling and may produce at most
                one block smaller than ``target_num_rows_per_block`` per input block without
                forcing exact sizes through block splitting.
                This parameter is only used with ``target_num_rows_per_block``.
                Defaults to ``False``.
            shuffle: Whether to perform a distributed shuffle during the
                repartition. When shuffle is enabled, each output block
                contains a subset of data rows from each input block, which
                requires all-to-all data movement. When shuffle is disabled,
                output blocks are created from adjacent input blocks,
                minimizing data movement.
            keys: List of key columns repartitioning will use to determine which
                partition will row belong to after repartitioning (by applying
                hash-partitioning algorithm to the whole dataset). Note that, this
                config is only relevant when `DataContext.use_hash_based_shuffle`
                is set to True.
            sort: Whether the blocks should be sorted after repartitioning. Note,
                that by default blocks will be sorted in the ascending order.

        Note that you must set either `num_blocks` or `target_num_rows_per_block`
        but not both.
        Additionally note that this operation materializes the entire dataset in memory
        when you set shuffle to True.

        Returns:
            The repartitioned :class:`Dataset`.
        """  # noqa: E501

        if target_num_rows_per_block is not None:
            if keys is not None: