Repository navigation
[data] Convert the write_sql and write_lance docstring examples to stock doctests - #67238
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the documentation examples for write_sql and write_lance in python/ray/data/dataset.py to use doctest-style syntax and temporary directories instead of hardcoded local files. The feedback suggests using with tempfile.TemporaryDirectory() context managers rather than manual instantiation and cleanup to ensure temporary resources are properly cleaned up even if exceptions occur during doctest execution.
dstrodtman
added a commit
that referenced
this pull request
Oct 29, 2026
…blocks (#67432) ## Description Converts the last `>>>` doctest examples on documentation pages, so `>>>` examples remain only in docstrings and on the two pages that teach the docstring format. #67429 changes the contributor guidance to match. This PR is independent of that stack and targets `master`. Before this PR, seven pages under `doc/source/` had `>>>` prompts. Two of them teach the docstring format and stay as they are: `ray-contribute/writing-code-snippets.md` and `ray-contribute/getting-involved.md`. This PR converts the other five: | Page | Before | After | Test coverage | |---|---|---|---| | `data/working-with-tensors.md` | Three `{doctest}` blocks | `{testcode}` and `{testoutput}` blocks | Unchanged. The `dtype` and shape checks still run. The two per-image shapes the doctest skipped are now a `+MOCK` sample. | | `ray-references/glossary.md` | One `{doctest}` block with `+SKIP` on every line | `{testcode}` and `{testoutput}` | Gained. The block used to run nothing and now runs. The expected output is unchanged, because Ray produces it exactly. | | `serve/advanced-guides/multi-app-container.md` | `>>>` prompts in a `python` fence, with every request skipped | Plain `python` and `text` blocks | None before or after. The requests need the containerized Serve apps running. The doctest only ran `import requests` and two string assignments. | | `core/tasks/nested-tasks.md` | REPL transcript in a `bash` block | Plain `python` and `text` blocks | None before or after. The page's `doc_code/` script is tested. | | `serve/production-guide/fault-tolerance.md` | Interactive `$ python` / `>>>` transcripts | Plain `python` blocks, with `text` blocks for output | None before or after. These steps kill actors on a live cluster. | ### Test wiring - `doc/BUILD.bazel`: - Removes the Serve `doctest_each` call. Its only file was `multi-app-container.md`, which no longer has a runnable example, so the target would pass without testing anything. - Drops the comment explaining why `nested-tasks.md` isn't listed, since the page no longer has anything runnable to explain. - The glossary and tensors entries stay, because both pages still have runnable examples. - `doc/test_prose_doctest_targets.py`: removes `nested-tasks.md` and `fault-tolerance.md` from `UNTESTED`. Neither page has a runnable example now. The two docstring-teaching pages stay exempt. No `.buildkite/test.rules.txt` change. All prose routes to `doc_example` whether or not a doctest target names the page, and the existing routing cases for these pages still hold. This PR edits `doc/BUILD.bazel`, so premerge runs every library's docs example step. The glossary target is tagged `team:none`, which runs only post-merge or with `docs-example-test`, so this PR carries that label too. ## Related issues Companion to #67429, which reserves `>>>` doctest-style examples for docstrings in the contributor guide. ## Additional information ### Duplicate check I searched open PRs for each converted page and for `doctest` in titles. #66705 edits `fault-tolerance.md` around line 53, far from these hunks. Draft #66851 appends a line to `nested-tasks.md` after these hunks. Neither converts these examples. The docstring conversion PRs (#67238, #66745, #67237) touch `python/`, not pages. ### Testing I reproduced the CI doctest runner locally: Ray 2.59.0, Python 3.11, `pytest==7.4.4`, `ray-project/pytest-sphinx@c1ab2b33`, the Ray Data `doctest_pytest_plugin.py`, and the macro's `--doctest-modules --doctest-glob='*.md' -c NO_PYTEST_CONFIG` arguments. - `working-with-tensors.md`: passes before (2 items: the doctest blocks and the testcode blocks) and after (1 item). A copy with a wrong expected shape fails with `Expected (32, 28, 99) / Got (32, 28, 28)`, so the new assertions are live. - `glossary.md`: before, 1 skipped. After, 1 passed. A copy with a wrong expected value fails. - `python doc/test_prose_doctest_targets.py`: "73 listed pages; every runnable page is accounted for." - `pre-commit run --files` on the changed files passes, including buildifier and buildifier-lint. - `vale` on each changed page: no new alerts compared with `master`. - After this PR, `git grep -l '^\s*>>> '` over `doc/source/*.md` and `*.rst` returns only the two pages that teach the docstring format. - The Read the Docs preview covers rendering. This PR was prepared with AI assistance (Claude Code). I reviewed every changed line. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
dstrodtman
force-pushed
the
doc-1862-data-write-sql-lance-doctests
branch
from
October 29, 2026 20:42
8e51870 to
bc9ec38
Compare
AarryaSaraf
approved these changes
Oct 29, 2026
dstrodtman
added a commit
that referenced
this pull request
Oct 30, 2026
…API (#67605) ## Summary Adds the missing docstrings, `Args:` entries, and `Returns:` sections on public Ray Data symbols in `aggregate`, `dataset`, `iterator`, `catalog`, `datasource`, `datatype`, and the public classes under `_internal`: the Databricks and LeRobot datasources and the object and tensor extensions. Each describes existing behavior, written from the code. It follows #67603, which covers the preprocessors. ## Before These symbols had no docstring, or their docstring had no section for some parameters or for the return value. `ApproximateQuantile` and `ApproximateTopK` kept their whole docstring on `__init__`, and the class reference page doesn't render that, so [their pages](https://docs.ray.io/en/master/data/api/doc/ray.data.aggregate.ApproximateQuantile.html) show no description. ## After The symbols are documented. The `ApproximateQuantile` and `ApproximateTopK` docstrings move, unchanged, from `__init__` to the class, so their pages show the description, examples, and arguments, and `__init__` drops out of their method tables. Where a base class lacked the docstring an override would inherit, this PR documents the base instead of each override: `Datasource.get_name`, `Datasource.estimate_inmemory_data_size`, `AggregateFn.output_field`, and `Catalog.resolve`. Behavior is unchanged. The diff touches only docstrings, which the guard below confirms. ## Subsystems API, IO, shuffle and aggregation, block and data format. Docstrings only. ## For reviewers These docstrings state behavior that looks unintended, so they're the ones worth a close read: - `PythonObjectArray.to_numpy` ignores `dtype`. - `ArrowPythonObjectArray.to_numpy` ignores `zero_copy_only` and `writable`. - `Dataset.__init__` now documents its arguments and keeps the note that the constructor isn't part of the public API. Three methods can't be documented without a signature change, so their code fixes and docstrings are in #67602: `ArrowPythonObjectScalar.as_py`, `ArrowTensorScalar.as_py`, and `ArrowPythonObjectArray.from_objects`. The `ArrowTensorScalar` class docstring sits directly above one of those signatures, so it's in #67602 too. #67602 also corrects the return annotation of `TensorArray.isna`, which this PR documents as returning a boolean NumPy array. ## Duplicate check No open PR documents these symbols. Open PRs #67600, #66927, #67238, and #67237 change other parts of `dataset.py`, and none of them edit the docstrings changed here. ## Testing - `python ci/ray_ci/doc/check_docstring_only.py --base "$(git merge-base upstream/master HEAD)"`: `docstring-only guard: 15 file(s), docstrings only.` - The full pre-commit suite on the changed files, including ruff, black, pydoclint, and the docstyle hook: passed. - The commit carries an `@rtd-build` line, so the Read the Docs preview renders the changed docstrings. AI assistance (Claude Code) was used to prepare this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
dstrodtman
force-pushed
the
doc-1862-data-write-sql-lance-doctests
branch
from
November 2, 2026 21:00
bc9ec38 to
d1c524c
Compare
goutamvenkat-anyscale
approved these changes
Nov 2, 2026
…ock doctests write_sql follows read_sql's pattern: it creates the SQLite database in a temporary directory and cleans it up in the example, in place of the hidden testcode block that deleted example.db from the working directory. write_lance's testcode directive had no blank line before its body and wrote to a fixed /tmp path. It now writes to a temporary directory too. These were the last testcode blocks in dataset.py. @rtd-build Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
dstrodtman
added a commit
that referenced
this pull request
Nov 3, 2026
…ttings in the examples runner (#67237) ## Description Follow-ups to the `docstring-only` label (#66814, #67083) after its first real campaign PRs on Ray Data. They're bundled into one PR because they share files and all need ray-ci review. Stacked on #67204, which updates the contributor docs this PR edits. 1. **Skip polars examples by name instead of marking them render-only.** `Dataset.join` needs `polars`, which the light `docstringbuild` image doesn't install, so #67202 marked the docstring `+SKIP_EXAMPLE`. That also stopped it from running in `//python/ray/data:doctest`, whose image installs polars through `test-requirements.txt`. This PR adds `polars` to `OMITTED_LIBRARIES` and removes the flag. The examples step now reports `SKIP Dataset.join (needs polars)`, and Data's target runs the three `join` examples. - Polars isn't added to the image. `polars==1.40.0` plus `polars-runtime-32==1.40.0` is a 57 MB x86_64 wheel and about 195 MB installed, larger than pyarrow at 136 MB, for one docstring. Every current extra is 21 MB or less. - **lance, the same way.** `Dataset.write_lance` needs `lance`, from the `pylance` distribution. It's about 138 MB installed on Linux aarch64, for one docstring, and Data's doctest image installs it through `data-test-requirements.txt`. This PR adds `lance` to `OMITTED_LIBRARIES`, so the examples step reports `SKIP Dataset.write_lance (needs lance)`. #67238, stacked on this PR, converts that docstring and `write_sql`'s from `testcode` to `>>>`. - **LightGBM and XGBoost, the same way.** `ray.tune.integration.lightgbm` and `.xgboost`, and Ray Train's LightGBM and XGBoost modules, import these at module level. The image installs neither, so a `docstring-only` change to one of those modules failed the examples step at import, even though Tune's examples there are render-only (`+SKIP_EXAMPLE`) and Train's are still `testcode`. The ML images install both through `python/requirements/ml/core-requirements.txt`, which meets the omit rule in item 2. The step now reports `SKIP python/ray/tune/integration/lightgbm.py (module needs lightgbm)`, and likewise for `xgboost`. #67619, stacked on this PR, converts those two Tune examples. 2. **Write the inclusion rule into `docstring-examples-requirements.txt`.** The header now states when to add a library to the image and when to omit it by name. Each entry names the APIs whose examples need it, so it can go once those stop needing it. Comment-only. `raydepsets --check` reports the locks unchanged. 3. **Apply Ray Data's doctest settings in the runner.** `doctest_pytest_plugin.py` sets `preserve_order` and turns off `print_on_execution_start` for every Data docstring. The runner applied neither, so an order-dependent example could pass in its target and flake in the step. It now applies both to `ray.data` modules and restores them after each docstring. 4. **`ml: data integration tests` under the label.** This PR originally added a negated `if:` gate to it. #67341 merged the `docstring-only` keep-only rule in `.buildkite/docs.labels.yaml`, which drops this step with every other library test step, so the gate is removed and `ml.rayci.yml` is unchanged. 5. **Count the output a render-only docstring hides.** `+SKIP_EXAMPLE` skips a whole docstring, so expected output inside it is never checked. The skip line now names how many such examples there are. Across `python/ray` at this commit, 26 docstrings carry the flag, and only `Dataset.join` had expected output, which item 1 makes runnable. So the count is a signal rather than a failure: a render-only example can legitimately show sample output, such as for an external service. 6. **`check_docstring_only.py --base` diffs from the merge base.** It diffed against the ref literally. After master moved past the branch point, `--base upstream/master` flagged files the PR never touched. The CI path, which already used the merge base, is unchanged. This matches `run_docstring_examples.py`, and the `ci.md` instructions drop the manual `git merge-base` wrapper. 7. **Stale comments.** The `doc_example` prose rule's comment in `test.rules.txt` said an unlabeled prose PR still builds the opt-in step's images. Since #67341, the `docs-example-test` label rule drops the step before dependency marking, so the comment now says that. The `doc: doctest` comment in `others.rayci.yml` still called `//doc:doctest` the catch-all target, but #67003 split it into per-page `team:none` targets. The `docstring examples` comment now names the omitted libraries. It also said Buildkite drops the step on an unlabeled PR that selects it, but Buildkite shows it as `broken`, and that the skipped Ray Data examples run in "postmerge", which now says the scheduled postmerge builds, since the build each merge starts doesn't run them. ## Related issues Related to #66814, #67083, #67202, and #67204. #67238 and #67619 are stacked on this PR. ## Additional information **Not a duplicate.** I searched open PRs for `run_docstring_examples`, `check_docstring_only`, `docstring-only`, `OMITTED_LIBRARIES`, and `data integration tests`. Only #67204, which this stacks on, touches these files, and it changes docs only. **Tests run** - `bazel test //ci/ray_ci/doc:test_run_docstring_examples //ci/ray_ci/doc:test_check_docstring_only`: both pass. New cases cover: - The `Dataset.join` polars message. - The hidden-output count. - The Data settings, applied and restored, and left alone for other modules. - `--base` against a base that moved past the branch point. - `missing_library` for `lightgbm` and `xgboost` module-level imports. For that commit I ran the suite with `pytest` directly rather than through Bazel: 33 passed. - `run_docstring_examples.py` on `dataset.py`, `aggregate.py`, and `read_api.py`. I ran it in an aarch64 image built from `docstring_examples_depset_py3.10.lock`, without `decord` (no aarch64 wheel) and `ray-haproxy`, with the Ray nightly at `093faf5583e`. - 114 docstrings ran, and `Dataset.join` skipped for polars. - The one failure is `read_videos`, which needs decord. The x86_64 CI image installs it. - With polars installed, `Dataset.join` passes, and 115 docstrings run. - With the Data settings, `Starting execution of Dataset` lines drop to zero, and all 18 `aggregate.py` docstrings pass. - `run_docstring_examples.py` on `ray.tune.integration.lightgbm` and `.xgboost` from #67619, in a Python 3.12 virtualenv with `ray[tune]==2.59.0` and neither library installed: both modules skipped by name, 0 failed. Before this change, both failed at import. - `bazel run //ci/raydepsets:raydepsets -- build ci/raydepsets/configs/docs.depsets.yaml --check`: lock files are up to date. - `pre-commit run` on the changed files: passes. - `rayci` v0.50.0 pipeline generation for a labeled Data docstring PR on this branch, as above. This PR's own premerge runs the Data and ML suites, because it changes `dataset.py`. That run is also the check that Data's doctest image has polars. AI assistance (Claude Code) was used for this PR. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Douglas Strodtman <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
dstrodtman
force-pushed
the
doc-1862-data-write-sql-lance-doctests
branch
from
November 3, 2026 11:49
d1c524c to
7d1a729
Compare
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.
Description
Converts the last three
.. testcode::blocks inpython/ray/data/dataset.pyto stock>>>doctests, inDataset.write_sqlandDataset.write_lance. After this,dataset.pyhas notestcodeleft. The change touches only docstrings.write_sqlfollowsread_sql's pattern. The example createdexample.dbin the working directory, and a hidden:hide:testcode block deleted it afterward. Stock doctests have no hidden-cleanup equivalent, so the example now creates the database in atempfile.TemporaryDirectory()and callscleanup()at the end, the wayray.data.read_sql's example does.write_lancewas malformed. Its.. testcode::directive had no blank line before its body. The example also wrote to a fixed/tmp/lance_data/path. It now writes to a temporary directory too. It needslance, which the docstring examples image doesn't install, so the examples step reports it as skipped by name, and//python/ray/data:doctest, whose image installspylance, runs it.Stacked on #67237, which adds
lanceto the runner'sOMITTED_LIBRARIES. Without that change, the examples step would fail onwrite_lancerather than skip it.Related issues
Related to #67202, #67207, #67209, and #67237.
Additional information
Not a duplicate. I searched open PRs for
write_sqlandwrite_lance. None converts these examples. #67202, #67207, and #67209 converted the rest ofdataset.pyand have merged.Tests run
ci/ray_ci/doc/check_docstring_only.py --base upstream/doc-1863-docstring-runner-bundle: "1 file(s), docstrings only."ci/ray_ci/doc/run_docstring_examples.py python/ray/data/dataset.pyin an aarch64 image built frompython/deplocks/docs/docstring_examples_depset_py3.10.lock, with the Ray nightly at093faf5583eand this branch'sdataset.pymounted over the installed one. Result: 64 docstrings run and 0 failed.write_sqlpasses, andwrite_lanceis skipped forlance.pylance==4.0.0installed, the version Ray Data's CI pins: 65 docstrings run, 0 failed, andwrite_lancepasses. Neither example leaves files in/tmp.pre-commit run --files python/ray/data/dataset.py: all hooks pass.The PR carries the
docstring-onlylabel, and its commit carries an@rtd-buildline for the Read the Docs preview.AI assistance (Claude Code) was used for this PR.
🤖 Generated with Claude Code