Skip to content

[cherry-pick][2.59.2][Data] Fix native tensor null rows on pyarrow 26 (#67806) - #68026

Merged
sai-miduthuri merged 1 commit into
sai-miduthuri/cherry-pick-67579-2.59.2from
sai-miduthuri/cherry-pick-67806-2.59.2
Nov 13, 2026
Merged

sai-miduthuri merged 1 commit into
sai-miduthuri/cherry-pick-67579-2.59.2from
sai-miduthuri/cherry-pick-67806-2.59.2

Conversation

@sai-miduthuri

Copy link
Copy Markdown
Contributor

Description

Cherry-pick of #67806 (master commit d0d059f) onto releases/2.59.2.

Top of a 3-PR stack on releases/2.59.2: #68024 (the #66521 pick), then #68025 (the #67579 pick), then this PR. Merging this PR with gh stack merge lands all three in order.

#67579 makes native_tensor_array_to_numpy return None for the null rows of a pyarrow-native tensor column. It calls to_numpy_ndarray() first. That reads null rows as zeros on pyarrow 23–25, but pyarrow 26 raises ArrowInvalid: Array contains nulls. Ray requires only pyarrow >= 17.0.0. So with FixedShapeTensorFormat.ARROW_NATIVE on pyarrow 26, the #67579 pick alone breaks batches with a null tensor row.

#67806 converts the same storage without its validity bitmap, which gives the dense array on every pyarrow version, and then fills in None as before.

Related issues

Related to #67806, the follow-up to #67579. The same pick for 2.60.1 is #68019, requested in this review on #67999.

Additional information

Cherry-pick details

Applied cleanly with git cherry-pick -x on top of the #67579 pick. It has the same 2 files, +21/-5, and the same git patch-id --stable as the master commit. It changes only native_tensor_array_to_numpy, which #67579 adds, and the test #67579 adds for it, so it needs nothing else from master.

Not a duplicate: neither this branch nor the stack below it contains #67806, and no PR against releases/2.59.2 references it. #68019 picks the same commit onto releases/2.60.1.

Testing

The six test files, under python/ray/data/tests/, are test_arrow_block.py test_tensor_extension.py test_torch_tensor_utils.py unit/test_transform_pyarrow.py test_transform_pyarrow.py test_pandas_block.py.

Command Result
pre-commit run --files <the 2 changed files> Passed
pytest <the six files>, pyarrow 23.0.1, with this PR 478 passed
pytest <the six files>, pyarrow 26.0.1, the #67579 pick without this PR 19 failed, 459 passed. All 19 are ARROW_NATIVE null-row tests that #67579 adds (test_batches_keep_tensor_column_* and test_native_tensor_array_to_numpy_with_null_rows)
pytest <the six files>, pyarrow 26.0.1, with this PR 478 passed

CI on this branch runs the Data tests on pyarrow 23.0.1 and 17.0.0, so it doesn't exercise this failure.

I ran these against the Ray 2.59.1 release wheel, with this branch's python/ray/data and python/ray/tests copied over it. The wheel was built from releases/2.59.1 at 7bdaad7, and its Python sources match releases/2.59.2 except for _version.py. The environment was Python 3.12 with pandas 2.3.3, numpy 2.1.3 and torch 2.9.0+cpu, with pyarrow 23.0.1 or 26.0.1. Building Ray from source for bazel test wasn't practical on my machine.

AI assistance was used to prepare this cherry-pick.

🤖 Generated with Claude Code

## Description

#67579 made `native_tensor_array_to_numpy` return `None` for the null
rows of a pyarrow-native tensor column. It calls `to_numpy_ndarray()`
first, which reads null rows as zeros on pyarrow 23–25 but raises
`ArrowInvalid: Array contains nulls` on pyarrow 26. So with
`ARROW_NATIVE` and pyarrow 26, any batch with a null tensor row now
fails, where it returned `None` before #67579. This converts the same
storage without its validity bitmap, which gives the dense array 23–25
returned on every version, and then fills in `None` as before.

## Related issues

Follow-up to #67579 ([review
comment](#67579 (comment))).

## Additional information

- Not a duplicate: no open PR or issue changes this function. #67293
handles native null rows elsewhere.
- Tests: Ray CI runs Data tests on pyarrow 17 and 23 (the nightly
pyarrow job is disabled), so the failure doesn't show there. Locally on
pyarrow 26, master fails 19 `ARROW_NATIVE` null-row tests in
`test_tensor_extension.py` and `test_arrow_block.py`; they pass with
this change. Eight related test files on pyarrow 17, 23 and 26 show no
other change.

<details>
<summary>Tests that also fail on unmodified master</summary>

- `test_tensor_array_scalar_cast` x3 (all versions)
- `test_tensors_sort[ARROW_NATIVE]` (pyarrow 26)
- `test_tensor_array_boolean_slice_pandas_roundtrip` x6 (pyarrow 17)

</details>

- AI assistance was used to prepare this PR.

Signed-off-by: rayo5o <[email protected]>
(cherry picked from commit d0d059f)
Signed-off-by: Sai Miduthuri <[email protected]>

@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 the native_tensor_array_to_numpy function in arrow.py to ensure compatibility with pyarrow 26, which rejects arrays with nulls outright. The implementation now extracts the underlying storage without its validity bitmap to perform the conversion and then replaces the null rows with None. Additionally, tests have been added in test_tensor_extension.py to cover sliced arrays and arrays containing only nulls. There are no review comments, and I have no further feedback to provide.

@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Nov 10, 2026
@sai-miduthuri sai-miduthuri added the go add ONLY when ready to merge, run all tests label Nov 10, 2026
@sai-miduthuri
sai-miduthuri merged commit 92aafec into releases/2.59.2 Nov 13, 2026
7 checks passed
@sai-miduthuri
sai-miduthuri deleted the sai-miduthuri/cherry-pick-67806-2.59.2 branch November 13, 2026 00:59
sai-miduthuri added a commit that referenced this pull request Nov 13, 2026
…conciliation and struct alignment (#66521) (#68024)

## Description

Cherry-pick of #66521 (master commit
6fa1a28) onto `releases/2.59.2`.

**Bottom of a 3-PR stack on `releases/2.59.2`:** this PR, then #68025
(the #67579 pick), then #68026 (the #67806 pick). Merge the stack with
`gh stack merge 68026`, which lands all three in order.

This is a prerequisite for the #67579 pick. #66521 fixes null-type
handling when Ray Data reconciles Arrow schemas across blocks:

- A nested field that is all-null in one block and a struct in another
crashes `_backfill_missing_fields` with `TypeError:
'pyarrow.lib.DataType' object is not iterable`.
- `_reconcile_field` reconciles `[null, list<null>, list<int64>]` to
`null` instead of `list<int64>`.

Without it, two of the tests #67579 adds fail on this branch. Both are
the case where one block's tensor column is fixed-shape, another's is
null, and a third's has a different shape. They fail with
`ArrowTypeError: Casting from
'extension<ray.data.arrow_variable_shaped_tensor<...>>' to different
extension type 'extension<ray.data.arrow_tensor_v2<...>>' not
permitted`.

## Related issues

Related to #66521. Needed by the #67579 pick. The same pick for 2.60.1
is #67995.

## Additional information

### Cherry-pick details

Applied cleanly with `git cherry-pick -x`. It has the same 2 files,
+233/-30, and the same `git patch-id --stable` as the master commit.

The two files differ from master at 6fa1a28 only by master commits
this change doesn't use: #66197, #66269 and #64961 in
`transform_pyarrow.py`, and #66269 in `unit/test_transform_pyarrow.py`.

Not a duplicate: this branch doesn't contain #66521, and no PR against
`releases/2.59.2` references it. #67995 picks the same commit onto
`releases/2.60.1`.

### Testing

| Command | Result |
|---|---|
| `pre-commit run --files <the 2 changed files>` | Passed |
| `pytest python/ray/data/tests/unit/test_transform_pyarrow.py
python/ray/data/tests/test_transform_pyarrow.py
python/ray/data/tests/test_arrow_block.py` | 123 passed |

The #67579 pick's description, #68025, has the results with the stack
applied.

I ran these against the Ray 2.59.1 release wheel, with this branch's
`python/ray/data` and `python/ray/tests` copied over it. The wheel was
built from `releases/2.59.1` at 7bdaad7, and its Python sources match
`releases/2.59.2` except for `_version.py`. The environment was Python
3.12 with pandas 2.3.3, pyarrow 23.0.1 and numpy 2.1.3, the versions CI
pins on this branch. Building Ray from source for `bazel test` wasn't
practical on my machine.

AI assistance was used to prepare this cherry-pick.

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

Signed-off-by: dragongu <[email protected]>
Signed-off-by: Sai Miduthuri <[email protected]>
Co-authored-by: dragongu <[email protected]>
sai-miduthuri added a commit that referenced this pull request Nov 13, 2026
…ble across blocks (#67579) (#68025)

## Description

Cherry-pick of #67579 (master commit
1acc2c3) onto `releases/2.59.2`.

**Middle of a 3-PR stack on `releases/2.59.2`:** #68024 (the #66521
pick), then this PR, then #68026 (the #67806 pick, which fixes this
change on pyarrow 26). Merge the stack with `gh stack merge 68026`,
which lands all three in order.

Since #61733 (2.56), a batch that spans blocks whose tensor column is
null in one of them fails with `ValueError: Trying to unify unsupported
tensor type: null`. A pandas UDF that returns `None` for some rows and
an ndarray for others is enough to hit it. It worked in 2.55.

#67579 lets tensor arrays carry null rows, so these blocks merge, the
column stays a tensor column, and missing rows read back as `None`.

## Related issues

Related to #67579. Depends on #68024, the #66521 pick. The same pick for
2.60.1 is #67999.

## Additional information

### Cherry-pick details

Applied with `git cherry-pick -x`. 5 of the 10 files merged cleanly. In
the other 5, each conflict was master-only code that sits next to
#67579's additions:

| File | Master-only context | Kept from #67579 |
|---|---|---|
| `arrow_ops/transform_pyarrow.py` | the `chunked_tensor_take` imports
(#64961) | the `create_ragged_ndarray` import |
| `tensor_extensions/arrow.py` | `tensor_array_to_numpy` and
`_to_dense_ndarray_or_none` (#66122) | `native_tensor_array_to_numpy` |
| `tensor_extensions/pandas.py` | the `TensorArray.dtype` docstring
reformat (#67539) | `first = _first_non_null(self._tensor)`, under this
branch's docstring |
| `tests/test_arrow_block.py` | earlier tests, such as #65539's | the 68
lines of new tests |
| `tests/test_tensor_extension.py` | #66122's tests | the 280 lines of
new tests |

I resolved each conflict by applying only #67579's change relative to
its parent, which was a pure insertion every time, and dropping the
master-only lines. Across all 10 files, the added and removed lines are
identical to the master commit. `git patch-id` differs only because of
the context lines.

Prerequisite: #66521. Without it,
`test_arrow_concat_tensor_with_null_keeps_tensor_type[last_shape1]` and
`test_unify_schemas_tensor_with_null_keeps_tensor_type[other_shape1]`
fail on this branch, as they do on 2.60.1.

Not a duplicate: this branch doesn't contain #67579, and no PR against
`releases/2.59.2` references it. #67999 picks the same commit onto
`releases/2.60.1`.

### Testing

The six test files, under `python/ray/data/tests/`, are
`test_arrow_block.py test_tensor_extension.py test_torch_tensor_utils.py
unit/test_transform_pyarrow.py test_transform_pyarrow.py
test_pandas_block.py`.

| Command | Result |
|---|---|
| `pre-commit run --files <the 10 changed files>` | Passed |
| `pytest <the six files>`, with the whole stack (#66521, this PR,
#67806) | 478 passed |
| `pytest --continue-on-collection-errors <the six files>`, with this
PR's tests against the code with only #66521 | 60 failed, 203 passed,
and `test_tensor_extension.py` fails to collect, because it imports a
helper this PR adds |
| `pytest <the six files>`, with this pick directly on
`releases/2.59.2`, without #66521 | The 2 tests above fail, 465 passed |
| `pytest test_arrow_block.py test_pandas_block.py
test_tensor_extension.py`, with the stack and the #67566 pick (#68022)
applied together | 365 passed |

I ran these against the Ray 2.59.1 release wheel, with this branch's
`python/ray/data` and `python/ray/tests` copied over it. The wheel was
built from `releases/2.59.1` at 7bdaad7, and its Python sources match
`releases/2.59.2` except for `_version.py`. The environment was Python
3.12 with pandas 2.3.3, pyarrow 23.0.1, numpy 2.1.3, scipy 1.17.1 and
torch 2.9.0+cpu, the versions CI pins on this branch. Building Ray from
source for `bazel test` wasn't practical on my machine.

AI assistance was used to prepare this cherry-pick.

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

Signed-off-by: Marwan Sarieddine <[email protected]>
Signed-off-by: Elliot Barnwell <[email protected]>
Signed-off-by: Sai Miduthuri <[email protected]>
Co-authored-by: Marwan Sarieddine <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
Co-authored-by: Elliot Barnwell <[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.

3 participants