Repository navigation
[Data] Fix TensorDtype.__from_arrow__ crash on empty tensor columns - #64767
Merged
elliot-barn merged 3 commits intoJul 16, 2026
Merged
elliot-barn merged 3 commits into
elliot-barn merged 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request fixes an issue where empty columns or per-row tensors with zero-size dimensions cause errors during Pandas round-trips. It replaces the use of -1 in reshape with an explicit row count and safely handles empty object arrays. A regression test is also added. The reviewer suggested simplifying the handling of empty arrays when num_rows == 0 to avoid unnecessary reshaping and ensure the correct data type is always returned.
Converting a tensor-extension column to pandas crashed when the column had zero-size elements (element_shape containing a 0, e.g. an operator emitting empty per-row tensors). `TensorDtype.__from_arrow__` reshaped with a `-1` dimension, which numpy cannot infer from a size-0 array, raising `ValueError: cannot reshape array of size 0 into shape (0)`. Reshape with the explicit row count instead of `-1`, and short-circuit the empty-block (num_rows == 0) case by building the correctly typed empty buffer directly (`np.stack` needs at least one array). Regressed in 2.56 by ray-project#61733. Closes ray-project#64766. Co-Authored-By: Claude Opus 4.8 <[email protected]> Signed-off-by: Marwan Sarieddine <[email protected]>
marwan116
force-pushed
the
data-fix-from-arrow-empty-tensor-64766
branch
from
July 15, 2026 11:10
ad0ca67 to
d5c8010
Compare
ayushk7102
approved these changes
Jul 15, 2026
ayushk7102
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thanks for the fix!
goutamvenkat-anyscale
approved these changes
Jul 15, 2026
goutamvenkat-anyscale
enabled auto-merge (squash)
July 15, 2026 20:28
elliot-barn
added a commit
that referenced
this pull request
Jul 16, 2026
…olumns (#64767) (#64794) Cherry-pick of #64767 onto the `releases/2.56.1` branch. ## Why are these changes needed? Fixes a 2.56 regression where converting tensor-extension columns to pandas crashed on zero-size tensor elements. Replaces numpy's `-1` dimension inference with an explicit row count and builds the buffer directly for empty arrays instead of using `np.stack`. ## Related issue number Cherry-pick of #64767 ## Checks Cherry-pick applied cleanly (no conflicts). DCO sign-off added. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Marwan Sarieddine <[email protected]> Signed-off-by: elliot-barn <[email protected]> Co-authored-by: Marwan Sarieddine <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]> Co-authored-by: Ayush Kumar <[email protected]>
400Ping
pushed a commit
to 400Ping/ray
that referenced
this pull request
Aug 18, 2026
…ay-project#64767) ## Description `Dataset.to_pandas()` (and any Arrow → pandas batch conversion) crashes on Ray 2.56 when a tensor-extension column has zero-size elements, i.e. `element_shape` contains a `0`. This happens naturally when a per-frame / per-group operator emits an empty tensor for some rows (e.g. a detection op that finds nothing in a frame). `TensorDtype.__from_arrow__` reshapes the reconstructed values with a `-1` dimension: ```python values = values.reshape((-1,) + self.element_shape) ``` numpy cannot infer a `-1` dimension from a size-0 array when another dimension is `0`, so this raises: ``` ValueError: cannot reshape array of size 0 into shape (0) ``` Minimal repro (fails on 2.56.0, worked on 2.55): ```python import ray, numpy as np ray.data.from_items([{"pts": np.zeros((0,), np.float32)} for _ in range(3)]).to_pandas() ``` This regressed in 2.56 via ray-project#61733, which added the reshape (2.55's `__from_arrow__` simply returned `TensorArray(values)` with no reshape). ## Related issues Closes ray-project#64766. ## Additional information The fix uses the explicit row count instead of `-1` (numpy no longer has to infer a dimension), and builds the empty buffer directly for the zero-row `object`-dtype case, since `np.stack` requires at least one array: ```python num_rows = len(array) if values.dtype == object: values = ( np.stack(values) if num_rows > 0 else np.empty((0,) + self.element_shape, dtype=self._dtype) ) values = values.reshape((num_rows,) + self.element_shape) ``` Added `test_tensors_in_tables_pandas_roundtrip_empty_elements`, parametrized over element shapes `(0,)` and `(0, 2)` plus the existing tensor-format (V1 / V2 / ARROW_NATIVE) and auto-cast fixtures. Verified locally that the V1 and V2 paths crash before this fix and pass after; the native `pa.fixed_shape_tensor` path did not crash (it does not route through `__from_arrow__`) and continues to work. Signed-off-by: Marwan Sarieddine <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]> Co-authored-by: Ayush Kumar <[email protected]> Signed-off-by: 400Ping <[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.
Description
Dataset.to_pandas()(and any Arrow → pandas batch conversion) crashes on Ray 2.56 when a tensor-extension column has zero-size elements, i.e.element_shapecontains a0. This happens naturally when a per-frame / per-group operator emits an empty tensor for some rows (e.g. a detection op that finds nothing in a frame).TensorDtype.__from_arrow__reshapes the reconstructed values with a-1dimension:numpy cannot infer a
-1dimension from a size-0 array when another dimension is0, so this raises:Minimal repro (fails on 2.56.0, worked on 2.55):
This regressed in 2.56 via #61733, which added the reshape (2.55's
__from_arrow__simply returnedTensorArray(values)with no reshape).Related issues
Closes #64766.
Additional information
The fix uses the explicit row count instead of
-1(numpy no longer has to infer a dimension), and builds the empty buffer directly for the zero-rowobject-dtype case, sincenp.stackrequires at least one array:Added
test_tensors_in_tables_pandas_roundtrip_empty_elements, parametrized over element shapes(0,)and(0, 2)plus the existing tensor-format (V1 / V2 / ARROW_NATIVE) and auto-cast fixtures. Verified locally that the V1 and V2 paths crash before this fix and pass after; the nativepa.fixed_shape_tensorpath did not crash (it does not route through__from_arrow__) and continues to work.