Skip to content

[data][doc] Correct the Dataset.union order and monotonically_increasing_id bit-split docstrings - #67532

Merged
dstrodtman merged 2 commits into
masterfrom
doc-1912-data-union-docstrings
Oct 30, 2026
Merged

dstrodtman merged 2 commits into
masterfrom
doc-1912-data-union-docstrings

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Corrects two Ray Data docstrings that disagree with the code. Dataset.union described the wrong output order and its skipped example showed it. monotonically_increasing_id gave the wrong bit width for the task ID. This is a docstring-only change. Behavior is unchanged.

This is separate from #67486, which corrects the prefetch_batches and local_shuffle_buffer_size docstrings.

Before

Dataset.union. The docstring said the order of the blocks in the datasets is preserved, "as is the relative ordering between the datasets passed in the argument list." Its example, marked +SKIP, showed range(2).union(range(3)) returning [0, 1, 0, 1, 2], all of the first dataset before the second. The code does neither:

  • Without preserve_order, UnionOperator._add_input_inner adds each input bundle straight to the output buffer as it arrives, so the order depends on scheduling.
  • With preserve_order, UnionOperator._try_round_robin takes one block from each input in argument order, then the next block from each, until every input runs out. range(2).union(range(3)) returns [0, 0, 1, 1, 2].

monotonically_increasing_id. The docstring said the task ID takes "the upper 31 bits." expression_evaluator.py sets TASK_BITS = 30 and ROW_BITS = 33, so the task ID takes the 30 bits above the record number, and the sign bit of the int64 is unused. The record-number half and the example output were already correct.

After

  • Dataset.union states both behaviors and names DataContext.execution_options.preserve_order as the switch. The example sets preserve_order, uses two-block inputs so the interleaving reads as block-level rather than row-level, and runs as a doctest:

    >>> ds1 = ray.data.range(4, override_num_blocks=2)
    >>> ds2 = ray.data.range(4, override_num_blocks=2)
    >>> [row["id"] for row in ds1.union(ds2).take_all()]
    [0, 1, 0, 1, 2, 3, 2, 3]
    >>> ctx.execution_options.preserve_order = False

    The example sets preserve_order itself rather than relying on doctest_pytest_plugin.py, so it's deterministic in any runner, including the data: docstring examples step, and resets the flag afterward, as streaming_train_test_split's example does.

  • monotonically_increasing_id says 30 bits for the task ID and notes the unused sign bit.

Subsystems

API (docstrings only).

Testing

  • Probe on Ray 2.59.0 (whose UnionOperator matches master's): range(2).union(range(3)).take_all() returned [0, 0, 1, 1, 2] in 5 of 5 runs with preserve_order=True. range(4, override_num_blocks=2).with_column("uid", monotonically_increasing_id()) returned uid values 0, 1, 8589934592, 8589934593, so the second task starts at 2**33.
  • New union example run through doctest against Ray 2.59.0 with ray.init(num_cpus=N) for N = 1, 4, and 16: 5 of 5 passes at each.
  • python ci/ray_ci/doc/check_docstring_only.py --base "$(git merge-base upstream/master HEAD)": 2 file(s), docstrings only.
  • python ci/ray_ci/doc/run_docstring_examples.py python/ray/data/dataset.py python/ray/data/expressions.py: PASS Dataset.union and PASS monotonically_increasing_id. The run had 84 PASS, 15 SKIP, and 7 FAIL. All 7 failures came from the local environment, not this change: Ray 2.59.0 lacks APIs that master has (unnest, write_orc), and the venv lacks Pillow and crc32c. CI runs these with this PR's Ray build in the Data image.
  • pre-commit run on both files: passes.

I didn't run //python/ray/data:doctest under Bazel locally.

Additional information

Not a duplicate. I searched open PRs for union preserve_order and monotonically_increasing_id and found nothing. #67486 touches different docstrings.

The commit carries an @rtd-build line so the preview renders the changed API pages. The PR carries the docstring-only label.

AI assistance (Claude Code) was used for this PR. I reviewed every changed line and ran the tests above.

🤖 Generated with Claude Code

…ing_id bit-split docstrings

Dataset.union said it keeps the relative order between datasets, and its
skipped example printed the first dataset's rows before the second's. With
preserve_order set, the union operator interleaves blocks round-robin
across its inputs; without it, the order isn't deterministic. The example
now sets preserve_order and runs.

monotonically_increasing_id said the task ID takes the upper 31 bits. The
evaluator reserves 30 bits for it above the 33-bit record number.

@rtd-build

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman requested a review from a team as a code owner October 29, 2026 13:24
@dstrodtman dstrodtman added docstring-only Skip heavy library tests for Ray API docstring edits. data Ray Data-related issues docs An issue or change related to documentation labels Oct 29, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the documentation and doctests for the union method in Dataset and the monotonically_increasing_id expression. Specifically, it clarifies how union interleaves blocks when preserve_order is enabled and updates the doctest example accordingly. It also clarifies the bit layout of IDs generated by monotonically_increasing_id. The review feedback suggests restoring the global DataContext configuration at the end of the doctest to prevent side effects on subsequent tests.

Comment thread python/ray/data/dataset.py Resolved
@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Oct 29, 2026
Matches the streaming_train_test_split example, which also restores the
flag after setting it.

@rtd-build

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman merged commit de72de2 into master Oct 30, 2026
6 checks passed
@dstrodtman
dstrodtman deleted the doc-1912-data-union-docstrings branch October 30, 2026 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues docs An issue or change related to documentation docstring-only Skip heavy library tests for Ray API docstring edits. go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants