Skip to content

[Data] Fix Dataset.summary() NotImplementedError on native fixed_shape_tensor with permutation - #68483

Open
industriverse wants to merge 2 commits into
ray-project:masterfrom
industriverse:fix/data-summary-native-tensor-pyarrow25-68280
Open

industriverse wants to merge 2 commits into
ray-project:masterfrom
industriverse:fix/data-summary-native-tensor-pyarrow25-68280

Conversation

@industriverse

Copy link
Copy Markdown

Description

On pyarrow 25+, Dataset.summary() raises NotImplementedError when building the type-preserving summary table for a dataset containing a native arrow.fixed_shape_tensor column with a permutation (created by pa.FixedShapeTensorArray.from_numpy_ndarray).

Because the tensor column has no type-preserving statistics, _build_summary_table(preserve_types=True) passes an all-None list to _create_pyarrow_array, which called pa.array([None, ...], type=tensor_type) and hit pyarrow 25's sequence-conversion guard.

This PR mirrors the pa.nulls approach from #68072:

  • When col_data is all None and col_type is specified, _create_pyarrow_array constructs the typed null array via pa.nulls(len(col_data), type=col_type).
  • Also catches NotImplementedError alongside (pa.ArrowTypeError, pa.ArrowInvalid) so unsupported sequence conversions cleanly fall back to convert_to_pyarrow_array.
  • Added regression test test_summary_native_fixed_shape_tensor_with_permutation in python/ray/data/tests/test_dataset_stats.py.

Related issues

Fixes #68280

Additional information

  • Verified locally on pyarrow==26.0.1 that _build_summary_table(..., preserve_types=True) produces a typed all-null extension<arrow.fixed_shape_tensor[value_type=int64, shape=[2,2], permutation=[0,1]]> column instead of raising NotImplementedError.

@industriverse
industriverse requested a review from a team as a code owner November 23, 2026 16:14

@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 resolves an issue where calling summary() on datasets containing native arrow.fixed_shape_tensor columns with permutations on pyarrow 25+ raises a NotImplementedError. It addresses this by using pa.nulls for all-null columns and catching NotImplementedError during PyArrow array creation. A regression test was added to verify the fix. The review feedback correctly points out a missing numpy import in the new test function, which would otherwise cause a NameError during execution.

Comment on lines +787 to +800
def test_summary_native_fixed_shape_tensor_with_permutation(
self, restore_data_context
):
"""Regression test for #68280: summary() must not raise NotImplementedError on
native arrow.fixed_shape_tensor columns with permutation on pyarrow 25+."""
from ray.data._internal.tensor_extensions.arrow import FixedShapeTensorFormat
from ray.data.context import DataContext

DataContext.get_current().arrow_fixed_shape_tensor_format = (
FixedShapeTensorFormat.ARROW_NATIVE
)
ds = ray.data.from_items(
[{"id": i, "emb": np.full((2, 2), i, dtype=np.int64)} for i in range(3)]
)

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.

high

The regression test uses np.full to construct the test dataset, but numpy is not imported in this test function or globally in the file. This will cause a NameError when the test is executed. Please import numpy as np within the test function.

Suggested change
def test_summary_native_fixed_shape_tensor_with_permutation(
self, restore_data_context
):
"""Regression test for #68280: summary() must not raise NotImplementedError on
native arrow.fixed_shape_tensor columns with permutation on pyarrow 25+."""
from ray.data._internal.tensor_extensions.arrow import FixedShapeTensorFormat
from ray.data.context import DataContext
DataContext.get_current().arrow_fixed_shape_tensor_format = (
FixedShapeTensorFormat.ARROW_NATIVE
)
ds = ray.data.from_items(
[{"id": i, "emb": np.full((2, 2), i, dtype=np.int64)} for i in range(3)]
)
def test_summary_native_fixed_shape_tensor_with_permutation(
self, restore_data_context
):
"""Regression test for #68280: summary() must not raise NotImplementedError on
native arrow.fixed_shape_tensor columns with permutation on pyarrow 25+."""
import numpy as np
from ray.data._internal.tensor_extensions.arrow import FixedShapeTensorFormat
from ray.data.context import DataContext
DataContext.get_current().arrow_fixed_shape_tensor_format = (
FixedShapeTensorFormat.ARROW_NATIVE
)
ds = ray.data.from_items(
[{"id": i, "emb": np.full((2, 2), i, dtype=np.int64)} for i in range(3)]
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch — added import numpy as np in test_summary_native_fixed_shape_tensor_with_permutation in b776011.

…e_tensor with permutation on pyarrow 25+

Signed-off-by: Kunal Kumar <[email protected]>
@industriverse
industriverse force-pushed the fix/data-summary-native-tensor-pyarrow25-68280 branch from cbf2042 to 81ca617 Compare November 23, 2026 16:18
@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Nov 24, 2026

@rayo5o rayo5o 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.

Checked this against the merge base (bebbc6e) on pyarrow 23.0.1, 24.0.0, 25.0.1 and 26.0.1, with 10 inputs (the issue repro, two tensor columns, a null tensor row, variable-shaped, mixed scalar types, columns=, multiple blocks) in V1, V2 and ARROW_NATIVE:

  • 23 and 24: output identical to the merge base.
  • 25 and 26: the merge base raises in 8 of the ARROW_NATIVE cases; this branch returns the same table as on 23. The only difference is the key order in the approx_topk dicts, which also differs between pyarrow versions for V1/V2 on the merge base.
  • pa.nulls vs pa.array([None] * n, type=t) for 19 types, including Ray's V1/V2/variable-shaped/object extension types: equal wherever pa.array works.

It isn't only ARROW_NATIVE users: with the default format (V2), reading a Parquet file whose tensor column was written by pyarrow (FixedShapeTensorArray.from_numpy_ndarray) gives the same NotImplementedError from summary() on the merge base with pyarrow 26, and works here.

On CI: premerge only runs the data tests in the arrow v23 lane (v25 is skip-on-premerge, v26 needs continuous-build), where the new test also passes on the merge base. Locally with the CI lock (pyarrow 25.0.1) it fails on the merge base and passes here; test_dataset_stats.py is 41 passed.

One suggestion on the test below.

min_row = actual[actual[DatasetSummary.STATISTIC_COLUMN] == "min"]
assert len(min_row) == 1
assert min_row["id"].iloc[0] == 0
assert pd.isna(min_row["emb"].iloc[0])

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.

This test still passes if I drop the pa.nulls block and keep only the extra NotImplementedError catch. In that version the emb column of the type-preserving table comes back as null instead of the tensor type, and to_pandas() looks the same either way. If keeping the type is what the pa.nulls path is for, two more lines would pin it (pass on b776011, fail with only the except change, pyarrow 25.0.1):

emb_type = summary._stats_matching_column_dtype.schema.field("emb").type
assert isinstance(emb_type, pa.FixedShapeTensorType)

This branch has not been deployed

No deployments
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Data] Dataset.summary() fails with NotImplementedError on native fixed shape tensor columns with pyarrow 25+

2 participants