Repository navigation
[data][doc] Correct the Dataset.union order and monotonically_increasing_id bit-split docstrings - #67532
Merged
Conversation
…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]>
Contributor
There was a problem hiding this comment.
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.
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]>
AarryaSaraf
approved these changes
Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Corrects two Ray Data docstrings that disagree with the code.
Dataset.uniondescribed the wrong output order and its skipped example showed it.monotonically_increasing_idgave 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_batchesandlocal_shuffle_buffer_sizedocstrings.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, showedrange(2).union(range(3))returning[0, 1, 0, 1, 2], all of the first dataset before the second. The code does neither:preserve_order,UnionOperator._add_input_inneradds each input bundle straight to the output buffer as it arrives, so the order depends on scheduling.preserve_order,UnionOperator._try_round_robintakes 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.pysetsTASK_BITS = 30andROW_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.unionstates both behaviors and namesDataContext.execution_options.preserve_orderas the switch. The example setspreserve_order, uses two-block inputs so the interleaving reads as block-level rather than row-level, and runs as a doctest:The example sets
preserve_orderitself rather than relying ondoctest_pytest_plugin.py, so it's deterministic in any runner, including thedata: docstring examplesstep, and resets the flag afterward, asstreaming_train_test_split's example does.monotonically_increasing_idsays 30 bits for the task ID and notes the unused sign bit.Subsystems
API (docstrings only).
Testing
UnionOperatormatches master's):range(2).union(range(3)).take_all()returned[0, 0, 1, 1, 2]in 5 of 5 runs withpreserve_order=True.range(4, override_num_blocks=2).with_column("uid", monotonically_increasing_id())returneduidvalues0, 1, 8589934592, 8589934593, so the second task starts at2**33.unionexample run throughdoctestagainst Ray 2.59.0 withray.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.unionandPASS 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 runon both files: passes.I didn't run
//python/ray/data:doctestunder Bazel locally.Additional information
Not a duplicate. I searched open PRs for
union preserve_orderandmonotonically_increasing_idand found nothing. #67486 touches different docstrings.The commit carries an
@rtd-buildline so the preview renders the changed API pages. The PR carries thedocstring-onlylabel.AI assistance (Claude Code) was used for this PR. I reviewed every changed line and ran the tests above.
🤖 Generated with Claude Code