Skip to content

[doc][data] Fix broken code examples in the Ray Data guides - #66636

Merged
dstrodtman merged 1 commit into
masterfrom
doc-1715-ray-data-broken-examples
Oct 2, 2026
Merged

dstrodtman merged 1 commit into
masterfrom
doc-1715-ray-data-broken-examples

Conversation

@dstrodtman

Copy link
Copy Markdown
Contributor

Why are these changes needed?

A style pass over the Ray Data guides (#66418, #66419, #66420, #66422, #66461) turned up code examples that are broken as written. They raise if you copy them, or they don't match what the surrounding text says. This PR fixes only those examples. It doesn't convert untested blocks to tests.

Page Problem Fix
loading-data.md GCS example uses gcsfs without importing it. Import it.
loading-data.md Azure example passes filesystem positionally, but it's keyword-only in read_parquet (TypeError). Pass it by keyword.
loading-data.md BigQuery dataset="bigquery-public-data.ml_datasets.iris". BigQueryDatasource reads dataset as dataset_id.table_id under project_id, so this resolves to dataset bigquery-public-data, table ml_datasets. Use a my_dataset.my_table placeholder, and say the format in the comment.
loading-data.md write_mongo example passes an undefined MongoDatasource(), and write_mongo has no such parameter. Remove it.
saving-data.md GCS and Azure examples use gcsfs and adlfs without importing them. Import them.
inspecting-data.md Output shows Image shape:, but the print has no colon. Add the colon to the print.
shuffling-data.md Key-based repartition on id, but ds is a read_images dataset with only image. It passed only because nothing consumed the dataset. Consumed, it raises KeyError: Field "id" does not exist. Use ray.data.range(1000) and materialize.
key-concepts.md Streaming example uses undefined UDF names and read_parquet(...), under a "1K rows" comment. Define placeholder UDFs and use ray.data.range(1000).
scaling-collation-functions.md Example reassigns dataset but passes train_dataset to the trainer. Use train_dataset throughout.
transforming-data.md Polars example: imports pl but calls polars. (NameError). from_pyarrow and DataFrame.summary don't exist in Polars. The block never consumed ds, so the UDF never ran. pl.from_arrow, describe(), and materialize.
transforming-data.md pandas map_groups example calls group.drop("target"), which drops rows by label and raises KeyError. group.pop("target"), which sets the column aside as the code intends. Materialize.

Duplicate check

Searched open PRs for each affected API and page (polars from_pyarrow, map_groups, gcsfs, read_bigquery, write_mongo, repartition, collation). Nothing open addresses these examples. #66614 and #66615 edited some of the same pages, but not these examples. Both have merged, and this branch is rebased on them.

Testing

Ran against the Ray nightly wheel (3.0.0.dev0, 674900c91fa) on macOS arm64, using the same pytest arguments and Data doctest plugin as the doctest_each targets in doc/BUILD.bazel, with pytest==7.4.4 and Ray's pytest-sphinx fork:

python -m pytest --doctest-modules --doctest-glob='*.md' --disable-warnings -c NO_PYTEST_CONFIG \
  -p doctest_pytest_plugin doc/source/data/<page>.md
  • loading-data.md, saving-data.md, inspecting-data.md, shuffling-data.md, and key-concepts.md pass, before and after the change.
  • transforming-data.md is in doctest[data-gpu] and stops at a CUDA block on a host without a GPU, before and after. So I ran its Iris setup block and the two changed blocks as a standalone doctest file, and it passes. Before the fix, those blocks raise NameError and KeyError once the dataset is consumed.
  • key-concepts.md streaming and scaling-collation-functions.md are untested python blocks. I ran the streaming block with num_gpus=1 removed, and it runs. The collation change is a rename, checked by reading.
  • The :skipif: True GCS, Azure, BigQuery, and MongoDB blocks need credentials, so I checked them against the current signatures in read_api.py and dataset.py and bigquery_datasource.py.
  • pre-commit run passes on the changed files.

This change touches only .md files, so premerge doesn't run the Data doc example tests.

AI assistance

Claude Code helped find the source for each fix, apply the edits, and run the tests. I reviewed every changed line.

🤖 Generated with Claude Code

Fix examples that raise or don't match what they claim:

- loading-data: import gcsfs; pass the Azure filesystem by keyword
  (read_parquet's filesystem is keyword-only); use the documented
  dataset_id.table_id form for read_bigquery; drop the undefined
  MongoDatasource() argument to write_mongo.
- saving-data: import gcsfs and adlfs.
- inspecting-data: make the print match the shown output.
- shuffling-data: key-based repartition example keyed on a column the
  read_images dataset doesn't have; use ray.data.range and materialize.
- key-concepts: define the streaming example's placeholder UDFs and use
  a 1K-row dataset to match its comment.
- scaling-collation-functions: pass the dataset the example reassigns.
- transforming-data: Polars example used an undefined name and two
  nonexistent Polars APIs (from_pyarrow, summary); map_groups example
  called group.drop("target"), which drops rows and raises KeyError.
  Executed blocks now consume their datasets so the doctest runs the UDF.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman
dstrodtman requested review from a team as code owners October 1, 2026 19:06

@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 several Ray Data documentation files to correct code snippets, add missing imports, fix Polars and Pandas API usages, and append .materialize() calls to ensure examples run properly. The feedback suggests renaming the row parameter to batch in the key concepts guide to accurately reflect that map_batches processes batches of data rather than individual rows.

Comment thread doc/source/data/key-concepts.md Resolved
@ray-gardener ray-gardener Bot added docs An issue or change related to documentation data Ray Data-related issues labels Oct 2, 2026
@dstrodtman dstrodtman added the go add ONLY when ready to merge, run all tests label Oct 2, 2026
@dstrodtman
dstrodtman merged commit f6b09e6 into master Oct 2, 2026
6 checks passed
@dstrodtman
dstrodtman deleted the doc-1715-ray-data-broken-examples branch October 2, 2026 19:00
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…ect#66636)

## Why are these changes needed?

A style pass over the Ray Data guides
([ray-project#66418](ray-project#66418),
[ray-project#66419](ray-project#66419),
[ray-project#66420](ray-project#66420),
[ray-project#66422](ray-project#66422),
[ray-project#66461](ray-project#66461)) turned up code
examples that are broken as written. They raise if you copy them, or
they don't match what the surrounding text says. This PR fixes only
those examples. It doesn't convert untested blocks to tests.

| Page | Problem | Fix |
|---|---|---|
| `loading-data.md` | GCS example uses `gcsfs` without importing it. |
Import it. |
| `loading-data.md` | Azure example passes `filesystem` positionally,
but it's keyword-only in `read_parquet` (`TypeError`). | Pass it by
keyword. |
| `loading-data.md` | BigQuery
`dataset="bigquery-public-data.ml_datasets.iris"`. `BigQueryDatasource`
reads `dataset` as `dataset_id.table_id` under `project_id`, so this
resolves to dataset `bigquery-public-data`, table `ml_datasets`. | Use a
`my_dataset.my_table` placeholder, and say the format in the comment. |
| `loading-data.md` | `write_mongo` example passes an undefined
`MongoDatasource()`, and `write_mongo` has no such parameter. | Remove
it. |
| `saving-data.md` | GCS and Azure examples use `gcsfs` and `adlfs`
without importing them. | Import them. |
| `inspecting-data.md` | Output shows `Image shape:`, but the print has
no colon. | Add the colon to the print. |
| `shuffling-data.md` | Key-based repartition on `id`, but `ds` is a
`read_images` dataset with only `image`. It passed only because nothing
consumed the dataset. Consumed, it raises `KeyError: Field "id" does not
exist`. | Use `ray.data.range(1000)` and materialize. |
| `key-concepts.md` | Streaming example uses undefined UDF names and
`read_parquet(...)`, under a "1K rows" comment. | Define placeholder
UDFs and use `ray.data.range(1000)`. |
| `scaling-collation-functions.md` | Example reassigns `dataset` but
passes `train_dataset` to the trainer. | Use `train_dataset` throughout.
|
| `transforming-data.md` | Polars example: imports `pl` but calls
`polars.` (`NameError`). `from_pyarrow` and `DataFrame.summary` don't
exist in Polars. The block never consumed `ds`, so the UDF never ran. |
`pl.from_arrow`, `describe()`, and materialize. |
| `transforming-data.md` | pandas `map_groups` example calls
`group.drop("target")`, which drops rows by label and raises `KeyError`.
| `group.pop("target")`, which sets the column aside as the code
intends. Materialize. |

## Duplicate check

Searched open PRs for each affected API and page (`polars from_pyarrow`,
`map_groups`, `gcsfs`, `read_bigquery`, `write_mongo`, `repartition`,
collation). Nothing open addresses these examples.
[ray-project#66614](ray-project#66614) and
[ray-project#66615](ray-project#66615) edited some of
the same pages, but not these examples. Both have merged, and this
branch is rebased on them.

## Testing

Ran against the Ray nightly wheel (`3.0.0.dev0`, `674900c91fa`) on macOS
arm64, using the same pytest arguments and Data doctest plugin as the
`doctest_each` targets in `doc/BUILD.bazel`, with `pytest==7.4.4` and
Ray's `pytest-sphinx` fork:

```bash
python -m pytest --doctest-modules --doctest-glob='*.md' --disable-warnings -c NO_PYTEST_CONFIG \
  -p doctest_pytest_plugin doc/source/data/<page>.md
```

- `loading-data.md`, `saving-data.md`, `inspecting-data.md`,
`shuffling-data.md`, and `key-concepts.md` pass, before and after the
change.
- `transforming-data.md` is in `doctest[data-gpu]` and stops at a CUDA
block on a host without a GPU, before and after. So I ran its Iris setup
block and the two changed blocks as a standalone doctest file, and it
passes. Before the fix, those blocks raise `NameError` and `KeyError`
once the dataset is consumed.
- `key-concepts.md` streaming and `scaling-collation-functions.md` are
untested `python` blocks. I ran the streaming block with `num_gpus=1`
removed, and it runs. The collation change is a rename, checked by
reading.
- The `:skipif: True` GCS, Azure, BigQuery, and MongoDB blocks need
credentials, so I checked them against the current signatures in
`read_api.py` and `dataset.py` and `bigquery_datasource.py`.
- `pre-commit run` passes on the changed files.

This change touches only `.md` files, so premerge doesn't run the Data
doc example tests.

## AI assistance

Claude Code helped find the source for each fix, apply the edits, and
run the tests. 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]>
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 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