Skip to content

[Data] Defer pyarrow.dataset load on import ray.data - #66463

Merged
dstrodtman merged 1 commit into
masterfrom
doc-1699-lazy-row-hash-import
Sep 24, 2026
Merged

dstrodtman merged 1 commit into
masterfrom
doc-1699-lazy-row-hash-import

Conversation

@dstrodtman

@dstrodtman dstrodtman commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

Since #66357, import ray.data loads pyarrow.dataset and its native extensions. The legacy parquet_datasource.py now imports _compute_row_hashes from the V2 readers package at module level, and the V2 reader modules import pyarrow.dataset at load time. Before #66357, the dependency ran the other way and ray.data never reached pyarrow.dataset on import.

This PR moves the _compute_row_hashes import into _read_batches_from, its only caller. That matches the file's existing function-level pyarrow.dataset imports. The import points at readers/synthesized_columns.py, where the helper has lived since #66390, rather than at the file_reader re-export. Importing from synthesized_columns at module level isn't enough on its own, because read_units.py also imports pyarrow.dataset at the top level.

It also adds test_import_does_not_load_pyarrow_dataset to python/ray/data/tests/test_import.py. The test asserts that a fresh driver's import ray.data loads no pyarrow._dataset* modules.

Why this matters

The Ray docs Read the Docs build has been segfaulting intermittently, in about 31% of builds since 2026-09-23. The crash is in native extension init while autosummary imports RLlib → Tune → AIR → ray.data. A PYTHONFAULTHANDLER=1 traceback (#66452) puts the crash inside from pyarrow._dataset_parquet import ..., which is reached from parquet_datasource.py → file_reader.py → import pyarrow.dataset. The loaded-extensions list in that traceback ends with exactly the modules this import adds.

This change takes the crashing import off the import ray.data path. It doesn't fix the underlying native crash. I couldn't reproduce it with a bare import pyarrow.dataset loop in linux/amd64 Docker: 0 of 300 runs failed, with numpy 2.2.6 and pyarrow 23.0.1 from the doc lock. So it seems to depend on process state or on the build host. The docs build and requirements_compiled.txt both pin pyarrow 23.0.1, and neither pin changed in the failure window.

Related issues

Related to #66357 and #66452.

Additional information

Not a duplicate

Searched open PRs for _compute_row_hashes, the DSv2 reorg series, and lazy-import and segfault keywords. #66450 (DSv2 Reorg [4/6]) and #66201 are the nearest open PRs, and neither touches this import or test_import.py.

Tests run

These were run locally on macOS arm64, Python 3.11, pyarrow 23.0.1, numpy 2.2.6. They used the Ray nightly wheel with ray/data and ray/tests linked from this branch.

  • pytest python/ray/data/tests/test_import.py: 2 passed. With the parquet_datasource.py change reverted, the new test fails and lists pyarrow._dataset, _dataset_orc, _dataset_parquet, and _dataset_parquet_encryption.

  • pytest python/ray/data/tests/datasource/test_parquet.py -k row_hash: 18 passed.

  • pytest python/ray/data/tests/datasource/test_parquet.py (full module): 242 passed, 13 skipped, 13 failed, 34 errors. Rerunning the 47 failing tests with master's parquet_datasource.py gave an identical failing set, so none come from this change. They come from the local environment:

    • The S3 fixtures error in fsspec's HTTP backend, because their test dependencies aren't installed.
    • Several local-path tests assert string columns and get large_string, which is pandas/pyarrow version skew against CI's pins.

    CI is the authoritative run for this module.

  • pre-commit run --files python/ray/data/_internal/datasource/parquet_datasource.py: all hooks passed, including ruff, black, pydoclint, and the import-order check.

AI assistance

AI assistance (Claude Code) was used to investigate the import graph, write the change and test, and draft this description. This PR stays in draft until the submitter has reviewed every changed line.

🤖 Generated with Claude Code

#66357 made the legacy parquet_datasource import _compute_row_hashes
from the V2 readers package at module level. The V2 reader modules
import pyarrow.dataset at load time, so every `import ray.data` now
loads PyArrow's dataset extensions (_dataset, _dataset_parquet,
_dataset_parquet_encryption, _acero, _substrait, and others).

Import the helper inside _read_batches_from, its only caller, and add
a regression test asserting `import ray.data` loads no
pyarrow._dataset* modules.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Signed-off-by: Douglas Strodtman <[email protected]>
@dstrodtman dstrodtman added data Ray Data-related issues go add ONLY when ready to merge, run all tests labels Sep 24, 2026
@dstrodtman
dstrodtman marked this pull request as ready for review September 24, 2026 17:35
@dstrodtman
dstrodtman requested a review from a team as a code owner September 24, 2026 17:35

@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 defers the loading of pyarrow.dataset when importing ray.data by moving the import of _compute_row_hashes from the module level to inside the _read_batches_from function in parquet_datasource.py, and updating its import path. Additionally, a unit test is added to verify that importing ray.data does not prematurely load pyarrow.dataset. There are no review comments, and I have no feedback to provide.

@dstrodtman
dstrodtman enabled auto-merge (squash) September 24, 2026 18:07
@dstrodtman
dstrodtman merged commit 46433ff into master Sep 24, 2026
6 of 7 checks passed
@dstrodtman
dstrodtman deleted the doc-1699-lazy-row-hash-import branch September 24, 2026 19:10
goutamvenkat-anyscale pushed a commit that referenced this pull request Sep 29, 2026
…mmon/ and formats/parquet/ (#66497)

## Description

`python/ray/data/_internal/datasource_v2/` grouped files by role
(`listing/`,
`scanners/`, `readers/`, `partitioners/`, `chunkers/`), and each role
folder
mixed the abstract class, the format-independent implementation and the
Parquet one. `listing/file_indexer.py` held `FileIndexer` next to
`NonSamplingFileIndexer`, with `FooterFileIndexer` two files over.
Someone
adding a format could not tell from the tree what they must implement,
what
they may reuse, and what is Parquet's business.

This PR regroups the package by kind: `interfaces/` is what a format
implements, `common/` is what it may reuse, `formats/<name>/` is one
folder
per format. `interfaces/` imports nothing else in the package, `common/`
imports only `interfaces/`, `formats/` may import both. No class,
signature
or behaviour changes; every import path changes.

### The layout

```
python/ray/data/_internal/datasource_v2/
  __init__.py                      InputSplit TypeVar (unchanged)
  README.md                        new: layout rule, how a read flows, what a format implements
  interfaces/                      abstract classes and the types their signatures use
    datasource_v2.py               DataSourceV2, DatasourceCategory, FileDataSourceV2, DataSourceWithMetadata
    scanner.py                     Scanner
    reader.py                      Reader
    file_indexer.py                FileIndexer, FileInfo
    file_pruner.py                 FilePruner
    file_partitioner.py            FilePartitioner, PartitionHints
    in_memory_size_estimator.py    InMemorySizeEstimator
    supports_metadata.py           SupportsMetadata, MetadataType
    pushdown.py                    SupportsFilterPushdown, SupportsColumnPushdown, SupportsLimitPushdown, SupportsPartitionPruning, ListFilesPushdown
    read_units.py                  ReadUnit, ReadUnitFragment
    synthesized_columns.py         SynthesizedColumn, ReadUnitPosition
    file_manifest.py               FileManifest, ChunkMetadata, create_chunk_metadata
  common/                          format-independent implementations
    non_sampling_file_indexer.py   NonSamplingFileIndexer
    listing_utils.py, indexing_utils.py
    file_pruners.py                FileExtensionPruner, PartitionPruner, PartitionPredicatePruner
    round_robin_partitioner.py     RoundRobinPartitioner
    online_bin_packer.py           OnlineBinPacker, BinItem, Bin
    size_estimators.py             SamplingInMemorySizeEstimator
    file_scanner.py                FileScanner
    arrow_file_scanner.py          ArrowFileScanner
    file_reader.py                 FileReader
    synthesized_columns.py         PathColumn, RowHashColumn
    pushdown_utils.py              derive_list_files_pushdown, combine_predicates
  formats/
    parquet/
      parquet_datasource_v2.py     ParquetDatasourceV2
      parquet_scanner.py           ParquetScanner
      parquet_file_reader.py       ParquetFileReader
      footer_file_indexer.py       FooterFileIndexer
      footer_reader.py             FooterReader actor
      parquet_footer_types.py      RowGroupInfo, FileChunks, ParquetRowGroupChunkMetadata
      parquet_size_estimator.py    ParquetInMemorySizeEstimator
      parquet_file_chunking_utils.py, parquet_row_group_coalescing.py, parquet_utils.py
```

### What changes
1. **32 renames** into the three folders; `git diff -M` pairs them, most
at 90%+ similarity with the rest being import lines.
2. **7 files split** where an interface sat next to its implementations:
`listing/file_indexer.py`, `listing/file_pruners.py`,
`readers/in_memory_size_estimator.py`, `readers/synthesized_columns.py`,
`logical_optimizers.py` (mixins to `interfaces/pushdown.py`, helpers to
`common/pushdown_utils.py`), `chunkers/file_chunker.py` (dissolved into
`interfaces/file_manifest.py` and
`formats/parquet/parquet_footer_types.py`) and
`chunkers/parquet_footer_types.py` (`BinItem`/`Bin` to
`common/online_bin_packer.py`).
3. **27 files outside the package** change import lines only:
`read_api.py`, the legacy `ParquetDatasource`, logical rules, planners,
tests. Tests keep their locations.
4. **Nine type errors fixed** in `common/indexing_utils.py`,
`common/non_sampling_file_indexer.py` and `interfaces/file_manifest.py`.
These three files were in `ci/lint/pyrefly-excluded-files.txt` under
their old paths, so the move puts them under pyrefly for the first time.
The fixes: re-raise after `_handle_read_os_error` returns instead of
reading an unbound `file_info`; the threaded lister always wraps results
in `OrderedFileResult` and unwraps on yield, so `input_path_index` is an
`int` and there is no `FileInfo | OrderedFileResult` union;
`FileManifest.__init__` asserts a `TableBlockAccessor` before calling
`column_names()`. `ci/` is not touched.
5. **`README.md`** (new) for the package.

One import still crosses the layering line:
`common/online_bin_packer.py` reads and writes
`ParquetRowGroupChunkMetadata` from `formats/parquet/`. The packer is
meant for any format with sized sub-file units, so it stays in
`common/`. A follow-up PR, once #66121 has settled the packer's fields,
adds a generic chunk-run type in `interfaces/` that the packer works on
and makes the Parquet type a subclass of it. Doing that here would turn
a reviewable set of renames into content changes.

## Additional information
Follows #66450 (`[4/6]`) and #66478 (`[5/6]`), both merged; the branch
sits directly on `master`. Not a duplicate: #62573 (WIP, `_internal/`
wide) does not touch `datasource_v2/`.

Checks run locally from this branch (macOS, `~/ray/.venv`):
```
pytest -q tests/unit/datasource_v2   # 146 passed
```
`ruff`, `black` and `pydoclint` at the pre-commit pins are clean on
every changed Python file; `tests/test_import.py` (from #66463) passes;
`pyrefly` via `ci/lint/pyrefly-check.sh` reports 59 errors, identical to
`master`, none new.

Written with Claude Code; I reviewed every changed line and ran the
tests above.

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

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…6463)

## Description

Since ray-project#66357, `import ray.data` loads `pyarrow.dataset` and its native
extensions. The legacy `parquet_datasource.py` now imports
`_compute_row_hashes` from the V2 readers package at module level, and
the V2 reader modules import `pyarrow.dataset` at load time. Before
ray-project#66357, the dependency ran the other way and `ray.data` never reached
`pyarrow.dataset` on import.

This PR moves the `_compute_row_hashes` import into
`_read_batches_from`, its only caller. That matches the file's existing
function-level `pyarrow.dataset` imports. The import points at
`readers/synthesized_columns.py`, where the helper has lived since
ray-project#66390, rather than at the `file_reader` re-export. Importing from
`synthesized_columns` at module level isn't enough on its own, because
`read_units.py` also imports `pyarrow.dataset` at the top level.

It also adds `test_import_does_not_load_pyarrow_dataset` to
`python/ray/data/tests/test_import.py`. The test asserts that a fresh
driver's `import ray.data` loads no `pyarrow._dataset*` modules.

### Why this matters

The Ray docs Read the Docs build has been segfaulting intermittently, in
about 31% of builds since 2026-09-23. The crash is in native extension
init while autosummary imports RLlib → Tune → AIR → `ray.data`. A
`PYTHONFAULTHANDLER=1` traceback (ray-project#66452) puts the crash inside `from
pyarrow._dataset_parquet import ...`, which is reached from
`parquet_datasource.py` → `file_reader.py` → `import pyarrow.dataset`.
The loaded-extensions list in that traceback ends with exactly the
modules this import adds.

This change takes the crashing import off the `import ray.data` path. It
doesn't fix the underlying native crash. I couldn't reproduce it with a
bare `import pyarrow.dataset` loop in `linux/amd64` Docker: 0 of 300
runs failed, with numpy 2.2.6 and pyarrow 23.0.1 from the doc lock. So
it seems to depend on process state or on the build host. The docs build
and `requirements_compiled.txt` both pin pyarrow 23.0.1, and neither pin
changed in the failure window.

## Related issues

Related to ray-project#66357 and ray-project#66452.

## Additional information

### Not a duplicate

Searched open PRs for `_compute_row_hashes`, the DSv2 reorg series, and
lazy-import and segfault keywords. ray-project#66450 (DSv2 Reorg [4/6]) and ray-project#66201
are the nearest open PRs, and neither touches this import or
`test_import.py`.

### Tests run

These were run locally on macOS arm64, Python 3.11, pyarrow 23.0.1,
numpy 2.2.6. They used the Ray nightly wheel with `ray/data` and
`ray/tests` linked from this branch.

* `pytest python/ray/data/tests/test_import.py`: 2 passed. With the
`parquet_datasource.py` change reverted, the new test fails and lists
`pyarrow._dataset`, `_dataset_orc`, `_dataset_parquet`, and
`_dataset_parquet_encryption`.
* `pytest python/ray/data/tests/datasource/test_parquet.py -k row_hash`:
18 passed.
* `pytest python/ray/data/tests/datasource/test_parquet.py` (full
module): 242 passed, 13 skipped, 13 failed, 34 errors. Rerunning the 47
failing tests with master's `parquet_datasource.py` gave an identical
failing set, so none come from this change. They come from the local
environment:
* The S3 fixtures error in `fsspec`'s HTTP backend, because their test
dependencies aren't installed.
* Several local-path tests assert `string` columns and get
`large_string`, which is pandas/pyarrow version skew against CI's pins.

  CI is the authoritative run for this module.
* `pre-commit run --files
python/ray/data/_internal/datasource/parquet_datasource.py`: all hooks
passed, including ruff, black, pydoclint, and the import-order check.

### AI assistance

AI assistance (Claude Code) was used to investigate the import graph,
write the change and test, and draft this description. This PR stays in
draft until the submitter has 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 (1M context) <[email protected]>
nadongjun pushed a commit to nadongjun/ray that referenced this pull request Oct 6, 2026
…mmon/ and formats/parquet/ (ray-project#66497)

## Description

`python/ray/data/_internal/datasource_v2/` grouped files by role
(`listing/`,
`scanners/`, `readers/`, `partitioners/`, `chunkers/`), and each role
folder
mixed the abstract class, the format-independent implementation and the
Parquet one. `listing/file_indexer.py` held `FileIndexer` next to
`NonSamplingFileIndexer`, with `FooterFileIndexer` two files over.
Someone
adding a format could not tell from the tree what they must implement,
what
they may reuse, and what is Parquet's business.

This PR regroups the package by kind: `interfaces/` is what a format
implements, `common/` is what it may reuse, `formats/<name>/` is one
folder
per format. `interfaces/` imports nothing else in the package, `common/`
imports only `interfaces/`, `formats/` may import both. No class,
signature
or behaviour changes; every import path changes.

### The layout

```
python/ray/data/_internal/datasource_v2/
  __init__.py                      InputSplit TypeVar (unchanged)
  README.md                        new: layout rule, how a read flows, what a format implements
  interfaces/                      abstract classes and the types their signatures use
    datasource_v2.py               DataSourceV2, DatasourceCategory, FileDataSourceV2, DataSourceWithMetadata
    scanner.py                     Scanner
    reader.py                      Reader
    file_indexer.py                FileIndexer, FileInfo
    file_pruner.py                 FilePruner
    file_partitioner.py            FilePartitioner, PartitionHints
    in_memory_size_estimator.py    InMemorySizeEstimator
    supports_metadata.py           SupportsMetadata, MetadataType
    pushdown.py                    SupportsFilterPushdown, SupportsColumnPushdown, SupportsLimitPushdown, SupportsPartitionPruning, ListFilesPushdown
    read_units.py                  ReadUnit, ReadUnitFragment
    synthesized_columns.py         SynthesizedColumn, ReadUnitPosition
    file_manifest.py               FileManifest, ChunkMetadata, create_chunk_metadata
  common/                          format-independent implementations
    non_sampling_file_indexer.py   NonSamplingFileIndexer
    listing_utils.py, indexing_utils.py
    file_pruners.py                FileExtensionPruner, PartitionPruner, PartitionPredicatePruner
    round_robin_partitioner.py     RoundRobinPartitioner
    online_bin_packer.py           OnlineBinPacker, BinItem, Bin
    size_estimators.py             SamplingInMemorySizeEstimator
    file_scanner.py                FileScanner
    arrow_file_scanner.py          ArrowFileScanner
    file_reader.py                 FileReader
    synthesized_columns.py         PathColumn, RowHashColumn
    pushdown_utils.py              derive_list_files_pushdown, combine_predicates
  formats/
    parquet/
      parquet_datasource_v2.py     ParquetDatasourceV2
      parquet_scanner.py           ParquetScanner
      parquet_file_reader.py       ParquetFileReader
      footer_file_indexer.py       FooterFileIndexer
      footer_reader.py             FooterReader actor
      parquet_footer_types.py      RowGroupInfo, FileChunks, ParquetRowGroupChunkMetadata
      parquet_size_estimator.py    ParquetInMemorySizeEstimator
      parquet_file_chunking_utils.py, parquet_row_group_coalescing.py, parquet_utils.py
```

### What changes
1. **32 renames** into the three folders; `git diff -M` pairs them, most
at 90%+ similarity with the rest being import lines.
2. **7 files split** where an interface sat next to its implementations:
`listing/file_indexer.py`, `listing/file_pruners.py`,
`readers/in_memory_size_estimator.py`, `readers/synthesized_columns.py`,
`logical_optimizers.py` (mixins to `interfaces/pushdown.py`, helpers to
`common/pushdown_utils.py`), `chunkers/file_chunker.py` (dissolved into
`interfaces/file_manifest.py` and
`formats/parquet/parquet_footer_types.py`) and
`chunkers/parquet_footer_types.py` (`BinItem`/`Bin` to
`common/online_bin_packer.py`).
3. **27 files outside the package** change import lines only:
`read_api.py`, the legacy `ParquetDatasource`, logical rules, planners,
tests. Tests keep their locations.
4. **Nine type errors fixed** in `common/indexing_utils.py`,
`common/non_sampling_file_indexer.py` and `interfaces/file_manifest.py`.
These three files were in `ci/lint/pyrefly-excluded-files.txt` under
their old paths, so the move puts them under pyrefly for the first time.
The fixes: re-raise after `_handle_read_os_error` returns instead of
reading an unbound `file_info`; the threaded lister always wraps results
in `OrderedFileResult` and unwraps on yield, so `input_path_index` is an
`int` and there is no `FileInfo | OrderedFileResult` union;
`FileManifest.__init__` asserts a `TableBlockAccessor` before calling
`column_names()`. `ci/` is not touched.
5. **`README.md`** (new) for the package.

One import still crosses the layering line:
`common/online_bin_packer.py` reads and writes
`ParquetRowGroupChunkMetadata` from `formats/parquet/`. The packer is
meant for any format with sized sub-file units, so it stays in
`common/`. A follow-up PR, once ray-project#66121 has settled the packer's fields,
adds a generic chunk-run type in `interfaces/` that the packer works on
and makes the Parquet type a subclass of it. Doing that here would turn
a reviewable set of renames into content changes.

## Additional information
Follows ray-project#66450 (`[4/6]`) and ray-project#66478 (`[5/6]`), both merged; the branch
sits directly on `master`. Not a duplicate: ray-project#62573 (WIP, `_internal/`
wide) does not touch `datasource_v2/`.

Checks run locally from this branch (macOS, `~/ray/.venv`):
```
pytest -q tests/unit/datasource_v2   # 146 passed
```
`ruff`, `black` and `pydoclint` at the pre-commit pins are clean on
every changed Python file; `tests/test_import.py` (from ray-project#66463) passes;
`pyrefly` via `ci/lint/pyrefly-check.sh` reports 59 errors, identical to
`master`, none new.

Written with Claude Code; I reviewed every changed line and ran the
tests above.

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

---------

Signed-off-by: Aarrya <[email protected]>
Co-authored-by: Claude Fable 5.1 <[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 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