Skip to content

[Data] Add HDF5 datasource support - #65760

Closed
YannByron wants to merge 3 commits into
ray-project:masterfrom
YannByron:feature/read-hdf5
Closed

YannByron wants to merge 3 commits into
ray-project:masterfrom
YannByron:feature/read-hdf5

Conversation

@YannByron

Copy link
Copy Markdown

Closes #65759.

Why

Ray Data doesn't currently have a native HDF5 reader. Users working with scientific, robotics, and machine-learning datasets must load HDF5 files on the driver or maintain a custom datasource.

This is not duplicate work: before implementation, open Ray issues and PRs were searched for HDF5, read_hdf5, and related Ray Data datasource terms, and no equivalent open implementation was found. The integration shape follows the merged read_lerobot work in #63821.

What changed

  • Add the public ray.data.read_hdf5 API and documentation.
  • Add an internal FileBasedDatasource that maps the selected HDF5 dataset's first axis to Ray Dataset rows.
  • Support multiple files, directory expansion, PyArrow filesystems, partitioning, included paths, scalar datasets, strings, and numeric variable-length arrays.
  • Plan reads using row count, target block size, and physical HDF5 chunks while reusing file handles within tasks.
  • Validate cross-file dtype and row shape, and fail closed for external storage, virtual datasets, references, null dataspaces, compound dtypes, and unsupported VLEN base dtypes.
  • Add Bazel wiring and the optional h5py Ray Data test dependency.

Tests

  • python -m pytest -q python/ray/data/tests/datasource/test_hdf5.py python/ray/data/tests/datasource/test_numpy.py — 45 passed.
  • ruff check python/ray/data/_internal/datasource/hdf5_datasource.py python/ray/data/tests/datasource/test_hdf5.py python/ray/data/read_api.py — passed.
  • python -m compileall -q python/ray/data/_internal/datasource/hdf5_datasource.py python/ray/data/read_api.py python/ray/data/tests/datasource/test_hdf5.py — passed.
  • git diff --check — passed.

Bazel wasn't available in the local environment. The repository pre-commit runner couldn't provision ruff-pre-commit because PyPI was unreachable; the equivalent local Ruff checks above passed.

AI assistance

AI assistance was used for research, implementation, tests, documentation, and iterative code review. This PR is intentionally opened as a draft and should not request maintainer review until the human submitter has reviewed every changed line and can explain and defend the change end-to-end, as required by the repository contribution policy.

@YannByron
YannByron marked this pull request as ready for review August 28, 2026 01:49
@YannByron
YannByron requested review from a team as code owners August 28, 2026 01:49

@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 introduces native support for reading HDF5 datasets into Ray Datasets by adding the read_hdf5 API and implementing HDF5Datasource. The implementation handles metadata inspection, parallel segment planning (aligning with HDF5 chunks and block sizes), and reading. A critical bug was identified in the read task generator where transient I/O retries via iterate_with_retry can cause silent data duplication by re-yielding already processed segments. A code suggestion has been provided to track completed segments and dynamically resume from the failed segment on retry.

@ray-gardener ray-gardener Bot added docs An issue or change related to documentation data Ray Data-related issues community-contribution Contributed by the community labels Aug 28, 2026
@YannByron

Copy link
Copy Markdown
Author

@ArturNiederfahrenhorst @richardliaw can you help to take a look, thx.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit 3819d45. Configure here.

biyan and others added 3 commits September 2, 2026 17:00
Add a public read_hdf5 API backed by a chunk-aware FileBasedDatasource.
Validate HDF5 schemas and unsafe storage modes, support Arrow-native string
and variable-length values, and cover the integration with focused tests.

Signed-off-by: biyan <[email protected]>
Co-Authored-By: Codex <[email protected]>
AI-Model: gpt-5.6-sol
Signed-off-by: biyan <[email protected]>
Co-Authored-By: Codex <[email protected]>
Co-Authored-By: Codex <[email protected]>
AI-Contributed/Feature: 654/654
AI-Contributed/UT: 811/811
Reject external links before dataset dereference, verify late-segment retries do not duplicate output, and add the required pytest entry point for semgrep.

Co-Authored-By: Codex <[email protected]>

AI-Model: gpt-5.6-sol

Signed-off-by: biyan <[email protected]>
Co-Authored-By: Codex <[email protected]>
Co-Authored-By: Codex <[email protected]>
AI-Contributed/Feature: 8/8
AI-Contributed/UT: 61/61
Inspect each dataset path component before dereferencing it, and reject external and soft links with focused regression coverage.

Co-Authored-By: Codex <[email protected]>

AI-Model: gpt-5.6-sol

Signed-off-by: biyan <[email protected]>
Co-Authored-By: Codex <[email protected]>
Co-Authored-By: Codex <[email protected]>
AI-Contributed/Feature: 40/40
AI-Contributed/UT: 39/39
@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Sep 16, 2026
richardliaw pushed a commit that referenced this pull request Sep 24, 2026
## Description

Style and grammar pass on Ray Data docs against Ray's [writing-style
guide](https://docs.ray.io/en/master/ray-contribute/writing-style.html).
Prose only: no code, `literalinclude` blocks, URLs, anchors, or role
targets changed.

Stacked on #66412, which is stacked on #66381, #66375, and #66352.
Review and merge those first. This branch targets
`doc-1524-data-vale-cleanup`. It combines this PR's original
comparisons-page pass with the custom datasource pass first opened as
#66416.

### `comparisons.md`

- Renames the legacy "Datasets" product name to "Ray Data". The page
already used "Ray Data" for the same subject in the same lists.
Third-party "Torch datasets" and "TensorFlow datasets" are unchanged.
- Fixes `SageMaker` and `BentoML` casing, which #66412 left as
intentional alerts for this pass.
- Uses contractions, active voice, second person, and "such as" for
examples.
- Removes "our blog post", "3rd", "e.g.", mid-sentence colons, and
semicolons.
- Fixes the grammar of the BentoML-and-Spark sentence and subject-verb
agreement for "TensorFlow datasets".
- Sentence-cases the dropdown titles and makes them parallel.
- Adds a lead-in sentence to each comparison list and uses the
`**Term**: explanation` definition-list form from the style guide.
- Collapses runs of blank lines between dropdowns to one.

### `custom-datasource-example.md`

This is the page whose `<!-- vale off -->` blocks #66412 removed so the
future-tense prose they hid could be fixed.

- Replaces the three "you'll" future-tense sentences with present tense.
- Names Ray Data as the actor in "file types that aren't natively
supported" and "Images are already supported".
- Replaces "functionality" with "behavior", "Once you've implemented"
with "After you implement", and the "(for example, `"png"`)"
parenthetical with "such as".
- Cuts the time-relative "in the future" from the write-interface note
but keeps "is under active development and might change", which is the
stability warning.
- Corrects the block types. The page said blocks can be dictionaries of
NumPy arrays, but `Block` in `block.py` is only a PyArrow table or a
pandas DataFrame, including at the commit the page links to. NumPy
dictionaries are a batch format. This is a factual correction.
- Sentence-cases the title: "Advanced: Read and write custom file
types".
- Updates the one link in `loading-data.md` whose text quotes the old
title.

## Why this isn't a duplicate

No other open PR edits `comparisons.md`, `custom-datasource-example.md`,
or `doc_code/custom_datasource_example.py`. #55038 adds an experimental
SQL API and SQL docs but doesn't edit these pages. See the related
question below. I also checked the open Data PRs that mention
datasources, including #65760, #57239, and #55467.

## Questions for reviewers

Apart from the block-types correction, this pass kept the scope of every
claim. These existing claims might be stale, and a Ray Data maintainer
is better placed to judge them:

- **Third-party feature claims on `comparisons.md`:** Petastorm supports
only Parquet, NVTabular supports only Parquet, CSV, and Avro, TensorFlow
datasets support only file interleaving across worker shards, and Torch
datasets have no I/O layer.
- **SQL interface:** "Ray Data doesn't have a SQL interface" would go
stale if #55038 lands.
- **Comparisons with no measure:** "a streaming paradigm that's better
suited to GPU workloads" and "can't effectively handle large datasets".
The style guide's "Keep comparisons precise" section applies, but no
source for a measure is on the page.
- **Repeated comparison points:** the training-ingest dropdowns repeat
three points almost word for word. A single comparison table might read
better. That moves content, so it isn't in this PR.
- **Duplicate headings:** `custom-datasource-example.md` has two H3s
named "Implement the constructor", one under reading and one under
writing. "Implement the datasource constructor" and "Implement the
datasink constructor" would make the right-side TOC clearer. I left them
as they are.

## Verification

- `vale` with Vale 3.12, run from the repo root: 0 alerts on
`comparisons.md`, down from 24, and 0 on `custom-datasource-example.md`,
down from 6. `loading-data.md` has no alerts on the edited line.
- `codespell`: no hits.
- The pre-commit hooks passed on each commit.
- A structural check against each pre-edit file confirmed the code-fence
count, role targets, anchors, and URLs are unchanged.
- For the reworded title, a grep for inbound links found the `{ref}` in
`loading-data.md`, updated here, and a toctree entry in `user-guide.md`,
which doesn't depend on the title. No links use the heading's implicit
slug.
- I didn't run a local Sphinx build. The Read the Docs preview covers
rendering.

## AI assistance

I made these edits with AI assistance (Claude Code) and reviewed the
full diff by hand.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
@github-actions

Copy link
Copy Markdown

This pull request has been automatically closed because there has been no more activity in the 14 days
since being marked stale.

Please feel free to reopen or open a new pull request if you'd still like this to be addressed.

Again, you can always ask for help on our discussion forum or Ray's public slack channel.

Thanks again for your contribution!

@github-actions github-actions Bot closed this Sep 30, 2026
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
## Description

Style and grammar pass on Ray Data docs against Ray's [writing-style
guide](https://docs.ray.io/en/master/ray-contribute/writing-style.html).
Prose only: no code, `literalinclude` blocks, URLs, anchors, or role
targets changed.

Stacked on ray-project#66412, which is stacked on ray-project#66381, ray-project#66375, and ray-project#66352.
Review and merge those first. This branch targets
`doc-1524-data-vale-cleanup`. It combines this PR's original
comparisons-page pass with the custom datasource pass first opened as
ray-project#66416.

### `comparisons.md`

- Renames the legacy "Datasets" product name to "Ray Data". The page
already used "Ray Data" for the same subject in the same lists.
Third-party "Torch datasets" and "TensorFlow datasets" are unchanged.
- Fixes `SageMaker` and `BentoML` casing, which ray-project#66412 left as
intentional alerts for this pass.
- Uses contractions, active voice, second person, and "such as" for
examples.
- Removes "our blog post", "3rd", "e.g.", mid-sentence colons, and
semicolons.
- Fixes the grammar of the BentoML-and-Spark sentence and subject-verb
agreement for "TensorFlow datasets".
- Sentence-cases the dropdown titles and makes them parallel.
- Adds a lead-in sentence to each comparison list and uses the
`**Term**: explanation` definition-list form from the style guide.
- Collapses runs of blank lines between dropdowns to one.

### `custom-datasource-example.md`

This is the page whose `<!-- vale off -->` blocks ray-project#66412 removed so the
future-tense prose they hid could be fixed.

- Replaces the three "you'll" future-tense sentences with present tense.
- Names Ray Data as the actor in "file types that aren't natively
supported" and "Images are already supported".
- Replaces "functionality" with "behavior", "Once you've implemented"
with "After you implement", and the "(for example, `"png"`)"
parenthetical with "such as".
- Cuts the time-relative "in the future" from the write-interface note
but keeps "is under active development and might change", which is the
stability warning.
- Corrects the block types. The page said blocks can be dictionaries of
NumPy arrays, but `Block` in `block.py` is only a PyArrow table or a
pandas DataFrame, including at the commit the page links to. NumPy
dictionaries are a batch format. This is a factual correction.
- Sentence-cases the title: "Advanced: Read and write custom file
types".
- Updates the one link in `loading-data.md` whose text quotes the old
title.

## Why this isn't a duplicate

No other open PR edits `comparisons.md`, `custom-datasource-example.md`,
or `doc_code/custom_datasource_example.py`. ray-project#55038 adds an experimental
SQL API and SQL docs but doesn't edit these pages. See the related
question below. I also checked the open Data PRs that mention
datasources, including ray-project#65760, ray-project#57239, and ray-project#55467.

## Questions for reviewers

Apart from the block-types correction, this pass kept the scope of every
claim. These existing claims might be stale, and a Ray Data maintainer
is better placed to judge them:

- **Third-party feature claims on `comparisons.md`:** Petastorm supports
only Parquet, NVTabular supports only Parquet, CSV, and Avro, TensorFlow
datasets support only file interleaving across worker shards, and Torch
datasets have no I/O layer.
- **SQL interface:** "Ray Data doesn't have a SQL interface" would go
stale if ray-project#55038 lands.
- **Comparisons with no measure:** "a streaming paradigm that's better
suited to GPU workloads" and "can't effectively handle large datasets".
The style guide's "Keep comparisons precise" section applies, but no
source for a measure is on the page.
- **Repeated comparison points:** the training-ingest dropdowns repeat
three points almost word for word. A single comparison table might read
better. That moves content, so it isn't in this PR.
- **Duplicate headings:** `custom-datasource-example.md` has two H3s
named "Implement the constructor", one under reading and one under
writing. "Implement the datasource constructor" and "Implement the
datasink constructor" would make the right-side TOC clearer. I left them
as they are.

## Verification

- `vale` with Vale 3.12, run from the repo root: 0 alerts on
`comparisons.md`, down from 24, and 0 on `custom-datasource-example.md`,
down from 6. `loading-data.md` has no alerts on the edited line.
- `codespell`: no hits.
- The pre-commit hooks passed on each commit.
- A structural check against each pre-edit file confirmed the code-fence
count, role targets, anchors, and URLs are unchanged.
- For the reworded title, a grep for inbound links found the `{ref}` in
`loading-data.md`, updated here, and a toctree entry in `user-guide.md`,
which doesn't depend on the title. No links use the heading's implicit
slug.
- I didn't run a local Sphinx build. The Read the Docs preview covers
rendering.

## AI assistance

I made these edits with AI assistance (Claude Code) and reviewed the
full diff by hand.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Signed-off-by: Douglas Strodtman <[email protected]>
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues docs An issue or change related to documentation stale The issue is stale. It will be closed within 7 days unless there are further conversation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Data] Add HDF5 datasource support

1 participant