Repository navigation
[data] Converge ray.data.read_api docstring examples to stock doctests - #67080
Merged
Merged
Conversation
Convert the 10 `.. testcode::` blocks in read_api.py to `>>>` doctests. The read_parquet pushdown example keeps its output check, and read_sql's hidden cleanup becomes a visible step. The seven `:skipif: True` blocks for external services (BigQuery, Snowflake, Databricks, Delta Sharing, Kafka) carry the docstring-level `+SKIP_EXAMPLE` flag instead. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
dstrodtman
marked this pull request as ready for review
October 15, 2026 16:14
Contributor
There was a problem hiding this comment.
Code Review
This pull request converts Sphinx .. testcode:: and .. testoutput:: blocks into standard Python doctest format (>>>) across several data-reading API docstrings, including read_bigquery, read_parquet, read_sql, read_snowflake, read_databricks_tables, read_delta_sharing_tables, and read_kafka. Feedback points out a redundant f-string prefix f in the read_delta_sharing_tables example that should be removed for cleaner code.
Create the example's SQLite database in a fresh temporary directory instead of the working directory, so a second run doesn't fail on the existing `movie` table, and add a `ds.count()` with its expected output. The example passes no shard keys, so the read task's metadata carries no row count and `count()` runs the read in a worker through `create_connection`. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
matthewdeng
approved these changes
Oct 15, 2026
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Douglas Strodtman <[email protected]>
dstrodtman
enabled auto-merge (squash)
October 15, 2026 17:44
dstrodtman
disabled auto-merge
October 15, 2026 18:36
This was referenced Oct 20, 2026
dstrodtman
added a commit
that referenced
this pull request
Oct 21, 2026
…EXAMPLE doctests (#67209) ## Description Converts the never-run `.. testcode::` / `:skipif: True` examples for Ray Data's external-service sinks and the Hive reader to `>>>` doctests. Each docstring is flagged once with the docstring-level `# doctest: +SKIP_EXAMPLE` from #66753. The change touches only docstrings: - **`python/ray/data/dataset.py`**: 10 blocks in `write_iceberg`, `write_delta`, `write_webdataset`, `write_snowflake`, `write_mongo`, `write_bigquery`, `write_clickhouse`, `write_turbopuffer` (2 blocks), and `write_kafka`. - **`python/ray/data/read_api.py`**: the `read_hive` example. - **`python/ray/data/_internal/datasource/turbopuffer_datasink.py`**: the 3 `TurbopufferDatasink` examples. Each example needs a service, credentials, or a bucket that CI doesn't have, so they stay render-only, as before. The flag is stripped at render time by both Sphinx (`trim_doctest_flags`) and griffe. The conversion follows the rules from #67080: same code in the same order, blank lines inside a block dropped, and top-level comments as `>>> #` lines. Two docstrings needed something other than the flag: - **The `Dataset` class docstring runs its example now.** That docstring also holds 10 runnable `>>>` examples, and `+SKIP_EXAMPLE` skips a whole docstring, so it would have stopped them from running. Instead, only the two lines that use placeholder paths, `read_parquet("s3://bucket/path")` and `write_csv("s3://bucket/output")`, carry `# doctest: +SKIP`. The `range` and `from_items` lines run. - **`write_csv`'s example had an unterminated string**, `"s3://bucket/folder/)`. It was already `+SKIP`, so nothing ever parsed it. The closing quote is now in place, so the docstring parses with the stock doctest parser. The `:skipif: True` blocks left in `dataset.py` after this PR are in #67202 (`join`) and #67207 (`streaming_split`). ## Related issues Related to #66753, #67080, #67202, and #67207. ## Additional information **Not a duplicate.** I searched open PRs for each method name, `turbopuffer`, `SKIP_EXAMPLE`, and `testcode skipif data`. #67202 and #67207 are my own and convert other methods in `dataset.py`. Two open PRs edit text these examples sit next to, so whichever PR lands second needs a small rebase: - #66192 edits the `write_iceberg` example's content, adding a REST catalog write. This PR changes only the example's form. - #66308 adds a deprecation notice to `write_clickhouse`, next to its example. #67114 and #67168 change `read_api.py` but not the `read_hive` docstring example. **Tests run** - `ci/ray_ci/doc/check_docstring_only.py --base upstream/master`: "3 file(s), docstrings only." - `ci/ray_ci/doc/run_docstring_examples.py` on the three files, in an aarch64 image with the Ray nightly at `093faf5583e` and the changed files mounted over the installed ones. None of the three files changed between that commit and this PR's base. Result: 85 docstrings run and 1 failed, with 16 skipped for `+SKIP_EXAMPLE` and 5 for an omitted library (torch, torchvision, TensorFlow, `tensorflow_datasets`). All 13 converted docstrings report `SKIP (+SKIP_EXAMPLE)`, and `Dataset` and `Dataset.write_csv` pass. The one failure is `read_videos`, which this PR doesn't touch. It needs `decord`, which has no aarch64 wheel. The run installed `datasketches`, `Pillow`, `crc32c`, `soundfile`, and `fastavro`, which the base image lacks. Without them, six more untouched docstrings fail on the missing import. - Every `>>>` example in the three files compiles with the stock `doctest` parser once `SKIP_EXAMPLE` is registered. - `pre-commit run --files` on the three files: all hooks pass, including ruff, black, pydoclint, and the Ray docstyle check. The PR carries the `docstring-only` label, and its commit carries an `@rtd-build` line for the Read the Docs preview. 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
added a commit
that referenced
this pull request
Oct 21, 2026
…ctests (#67208) ## Description Converts the seven `.. testcode::` examples in `python/ray/data/llm.py` to `>>>` doctests. They're in `HttpRequestProcessorConfig`, `vLLMEngineProcessorConfig`, `SGLangEngineProcessorConfig`, `ServeDeploymentProcessorConfig`, and `build_processor`, which holds three of them. The change touches only docstrings. **The examples stay render-only.** Every block was `:skipif: True`, because running them needs GPUs and model downloads, an OpenAI API key, or a running Serve deployment. Each docstring now carries one `# doctest: +SKIP_EXAMPLE` flag on its first line, which skips the whole docstring in both the `//python/ray/data:doctest` target and the `docstring-only` examples step. Sphinx strips the flag from the rendered page. The code itself is unchanged apart from the `>>>` and `...` prompts and the removal of the blank lines a doctest can't contain. This is separate from the other Ray Data docstring conversions, such as #67202 and #67207, because CODEOWNERS assigns `python/ray/data/llm.py` to `@ray-project/ray-llm`. ## Related issues Related to #67080, #67202, and #67207. ## Additional information **Not a duplicate.** I searched open PRs that mention `llm.py` or converting `ray.data.llm` docstring examples. None touches these examples. **Tests run** - `ci/ray_ci/doc/check_docstring_only.py --base upstream/master`: "1 file(s), docstrings only." - `ci/ray_ci/doc/run_docstring_examples.py python/ray/data/llm.py` against the macOS arm64 Ray nightly at `43b706d733c`, whose `llm.py` matches this PR's base, with the converted file swapped in: 0 run, 0 failed, 5 skipped for `+SKIP_EXAMPLE`. - `pytest --doctest-modules -p doctest_pytest_plugin` on the same file, with the Ray Data doctest plugin: 5 skipped as "render-only example (+SKIP_EXAMPLE)", no collection errors. - Every converted example parses with `doctest.DocTestParser` and compiles. - `pre-commit` on commit: all hooks pass, including black, ruff, and the Ray docstyle check. The PR carries the `docstring-only` label, and its commit carries an `@rtd-build` line for the Read the Docs preview. 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
added a commit
that referenced
this pull request
Oct 21, 2026
…examples to stock doctests (#67207) ## Description Converts the remaining runnable `.. testcode::` examples in nine `Dataset` methods to stock `>>>` doctests: `streaming_split`, `split`, `iter_batches`, `iter_jax_batches`, `iter_tf_batches`, `stats`, `explain`, `serialize_lineage`, and `deserialize_lineage`. It also converts the one example each in `SerializablePreprocessorBase._set_serializable_fields` (`preprocessor.py`) and `MemoryProfiler` (`_internal/util.py`). Stock doctests render without Sphinx-only directives, and the `docstring-only` label's examples step runs them. The change touches only docstrings. Three examples used `:options: +MOCK`, which hid their output from comparison. Comparing it surfaced the following fixes: - **`iter_batches`** read `example://image-datasets/simple`, which resolves inside the installed package, and wheels don't ship `ray/data/examples/data/`. It now reads the same images from `s3://anonymous@ray-example-data/image-datasets/simple`, as `Dataset.map` does. The three images make exactly two batches, so the expected output drops the `...` line between them, which wouldn't have matched. - **`stats`** shows the current output format, with ellipses for counts, timings, and the read operator's name, which becomes `ReadRange->SplitBlocks(N)` depending on the CPU count. The `assert ds.stats() == ""` is now `>>> ds.stats()` with `''` as the output. - **`MemoryProfiler`** replaces the `...` placeholder statement with `pass`. In a doctest, a bare `...` expression echoes `Ellipsis` on every loop iteration. The USS values use an ellipsis. **`iter_tf_batches`** called `Dataset.to_tf`, which has its own examples. It now calls `iter_tf_batches` and prints the first batch, matching the `iter_jax_batches` example. The fourth `streaming_split` example deliberately blocks, so it stays render-only, now with `# doctest: +SKIP` on that one line in place of `:skipif: True`. The rest of the docstring runs. `explain`, `split`, and the lineage examples matched as written. **`iter_jax_batches` and `iter_tf_batches` run only in postmerge under the label.** The docstring examples image omits JAX and TensorFlow, so the step skips both docstrings by name. They still run in `//python/ray/data:doctest`. ## Related issues Related to #66814, #67083, and #67202. ## Additional information **Not a duplicate.** I searched open PRs that touch `python/ray/data/dataset.py`, `streaming_split`, `serialize_lineage`, or `MemoryProfiler`. #67202 converts the `Dataset` transform methods (`map`, `map_batches`, `flat_map`, `groupby`, `aggregate`, `join`) in the same file, and the two PRs edit different methods. #64869 and #66340 don't touch these examples. #66746, #66812, #67070, and #67080 converted other Data modules and have merged. **Tests run** - `ci/ray_ci/doc/check_docstring_only.py --base upstream/master`: "3 file(s), docstrings only." - `ci/ray_ci/doc/run_docstring_examples.py` on the three files in an aarch64 image built from `python/deplocks/docs/docstring_examples_depset_py3.10.lock`, with the Ray nightly at `093faf5583e` and the changed files mounted over the installed ones. The three files are unchanged between that commit and this PR's base. Result: 61 docstrings run and 0 failed. `iter_jax_batches`, `iter_tf_batches`, `to_tf`, `write_tfrecords`, and `iter_torch_batches` are skipped for libraries the image omits. - The two JAX and TensorFlow docstrings, run with `doctest` in the same image after installing `jax` 0.6.2 and `tensorflow` 2.21.0: 0 failures each. Those aren't CI's pinned versions, so I'll check the postmerge `data: docs example tests` result after merge. - `pre-commit run --files` on the three files: all hooks pass, including ruff, black, pydoclint, and the Ray docstyle check. The PR carries the `docstring-only` label, and its commit carries an `@rtd-build` line for the Read the Docs preview. 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]>
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.
What
Convert the 10
.. testcode::blocks inpython/ray/data/read_api.pyto stock>>>doctests:read_parquet: the projection and filter pushdown example joins the docstring's existing>>>session, and itstestoutputbecomes the expected output, so theshow(2)result is still checked.read_sql: the SQLite example, which now creates its database in a temporary directory and checks one read withds.count(). See below.read_bigquery,read_snowflake,read_databricks_tables(2 blocks),read_delta_sharing_tables, andread_kafka(2 blocks)::skipif: Trueexamples that need an external service or credentials. Each docstring carries the docstring-level# doctest: +SKIP_EXAMPLEflag from [core] Add a docstring-level +SKIP_EXAMPLE doctest flag for render-only examples #66753 once. None of these five docstrings has another>>>example for the flag to skip by accident.Why
This continues the convergence in #66746, #66812, and #67070, with the same conversion rules: same code, same order, same docstring, blank lines inside a block dropped, bare expressions with an incidental repr bound to
_, and each example under a pluralExamples:header with no blank line after it.read_snowflake's singularExample:header becomesExamples:.For the label from #66814, this is a larger case than #67070. The runner runs every docstring in a changed file, so it runs all 35 runnable docstrings in
read_api.py, not only the 10 converted blocks. It also checks output onread_parquetand runs five+SKIP_EXAMPLEdocstrings.Design choices for review
read_sqlcreates its database in a temporary directory. The original wroteexample.dbto the working directory and removed it in a hidden.. testcode:: :hide:block, because a second run in the same directory fails onCREATE TABLE movie("table movie already exists"). Stock doctest has no run-but-hide form. The example now opensos.path.join(db_dir.name, "example.db")under atempfile.TemporaryDirectory()and ends withdb_dir.cleanup(), so it can be rerun by readers as well as in CI, with no test-harness change. An in-memory SQLite database wouldn't work:read_sqlcallsconnection_factoryinside each read task, in a worker process, so each worker would open a new empty database. The sameTemporaryDirectorypattern is in [data] Converge small ray.data module docstring examples to stock doctests #66812'slist_stats_summaries.read_sqlnow checks a read. The example never consumed the datasets it built, so it didn't show that a read works. It now callsds.count()on the all-movies query and expects4. With noshard_keys,read_sqlfalls back to a single read task whose metadata has no row count, socount()runs that task in a worker and opens the database throughcreate_connection. On a warm local cluster the count takes about 1 second.connection.execute(...)calls are bound to_. As a statement intestcodethey printed nothing, but as>>>they'd echo asqlite3.Cursorrepr with a memory address.Duplicate check
I searched open PRs for
read_api,read_sql,read_kafka, andtestcode doctest data. #66604 touchedread_api.pybut is merged and changed different text. The only related open PRs are my own #66746, #66812, and #67070, which touch other files.Tests run
Locally against a Ray nightly (
43b706d) on Python 3.12, using pytest 7.4.4 and the same flags as thedoctestBazel macro,--doctest-modules -c NO_PYTEST_CONFIG -p <Ray Data doctest plugin>, with both collectors installed.master'sread_api.pyimportsray.data.checkpoint.generated_id, which that nightly predates, so I applied this PR's diff to the nightly's ownread_api.pyrather than overlayingmaster's copy.-p no:sphinxread_parquetandread_sqlalone, each collector setupread_sqlrun twice in the same directory,-W error::ResourceWarningexample.dbleft in the working directoryci/ray_ci/doc/check_docstring_only.py --base upstream/masterThe pass count drops by one because
pytest-sphinxcollected theread_parquetandread_sqltestcodeblocks as two extra items. They're now part of the stock doctest items, one per docstring, andread_sqlgains a stock item it didn't have. The five:skipif: Trueblocks were dropped before collection and never reported. They now report as skipped.The same five docstrings fail before and after, all in docstrings this PR doesn't touch, because of my local environment:
from_tf(tensorflow_datasets),read_audio(soundfile),read_avro(fastavro),read_videos(decord), andread_json, whoseds.schema()printsstringwhere the docstring expectsobjectbecause of a newer local pandas. Therun_docstring_examples.pyrunner on the file reports 35 docstrings run, with the same five failures and five skips.pre-commitpasses on the changed file.AI assistance. This change was drafted with Claude Code. I reviewed every line and ran the tests above.
🤖 Generated with Claude Code