Skip to content

[Data] Log the conflicting column and types on schema unification error - #67647

Merged
goutamvenkat-anyscale merged 4 commits into
ray-project:masterfrom
ayushk7102:log_schema_unification_error
Nov 3, 2026
Merged

goutamvenkat-anyscale merged 4 commits into
ray-project:masterfrom
ayushk7102:log_schema_unification_error

Conversation

@ayushk7102

Copy link
Copy Markdown
Contributor

Summary

When blocks can't be merged because a column has different types in different blocks, the error now names every conflicting column and the types it had, with block counts. Before, the message was cut off at 200 characters, which usually hid the type causing the conflict.

Before

ArrowConversionError: Error converting data to Arrow: Failed to unify schemas: Found columns with both objects and tensors: pts
----------------
Schemas:
----------------
[id: int64
pts: extension<ray.data.arrow_pickled_object<ArrowPythonObjectType>>, id...
  • ArrowConversionError truncates its message to 200 characters, so the raw schema dump stops after the first schema and the conflicting tensor type never appears.
  • The object/tensor check in _reconcile_diverging_fields raises on the first conflicting column, so other conflicting columns go unreported.
  • A printed pa.Schema shows extension types as extension<ray.data.arrow_tensor_v2<...>>, without shape or dtype.

After

ArrowSchemaUnificationError: Failed to unify schemas across 3 blocks.
Columns with incompatible types:
  - 'pts': extension<ray.data.arrow_pickled_object<ArrowPythonObjectType>> (1 block), ArrowTensorTypeV2(shape=(2, 4, 3), dtype=double) (1 block), null (1 block)
Cause: Found columns with both objects and tensors: pts
  • concat raises the new ArrowSchemaUnificationError, a subclass of ArrowConversionError that skips the truncation. Existing except ArrowConversionError handlers (e.g. the pandas fallback in block.py) still catch it.
  • The message lists each column whose type differs across blocks (up to 20), with each type's str() (tensor shape and dtype included) and how many blocks had it.
  • The object/tensor ValueError now names all conflicting columns, not just the first.
  • The new code only runs after unification has already failed, so the success path is unchanged.

Subsystems

Block / data format

Related work

Not a duplicate. #67579 makes tensor columns with null rows mergeable and notes that "a follow-up PR extends that error with the columns and types found". This is that follow-up. No other open PR changes this error message.

Testing

pytest python/ray/data/tests/unit/test_transform_pyarrow.py
118 passed
  • Added test_concat_objects_and_tensors_error_lists_columns_and_types: two conflicting columns, checks the header, that both columns are named, and the full type list for each.
  • Existing tests matching Failed to unify schemas and Found columns with both objects and tensors still pass.
  • Manual repro (pandas UDF returning a ragged list, a stacked array, and None across three blocks) produces the "After" message above.

AI assistance (Claude Code) was used to write this change. I reviewed every line and ran the tests above.

@ayushk7102
ayushk7102 requested a review from a team as a code owner October 31, 2026 00:43
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@ray-gardener ray-gardener Bot added the data Ray Data-related issues label Oct 31, 2026

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

The change is the right shape and the new message is a real improvement. I checked out the head, ran the unit transform file, test_transform_pyarrow.py, test_arrow_block.py and test_map_batches.py, and reproduced the failing case (tensor, pickled object and null in the same column across three blocks). The message comes out exactly as the body shows, with the tensor shape and dtype and the block counts.

One blocking item, one coordination note, two nits. Details inline.

Blocking. test_pyarrow_conversion_error_handling[map_batches-data4-True-None] in python/ray/data/tests/test_transform_pyarrow.py fails on this branch and passes on master. It asserts that the user-facing error contains ArrowConversionError: Error converting data to Arrow:. With this PR the class in the traceback is ArrowSchemaUnificationError and the message starts with Failed to unify schemas across 2 blocks.. The body's test line only covers the unit file, which is why it was missed.

Coordination. This conflicts with #67579 in transform_pyarrow.py, since both touch the object-versus-tensor check. This PR is the smaller change, so I suggest it lands first and I rebase #67579 onto it and adopt the after-the-loop check.

Nits.

  • The "Before" example in the body shows a null arm next to the tensor. Once #67579 lands, tensor plus null merges into a tensor column with null rows, so that example will show a conflict that no longer exists. A tensor next to a pickled object alone makes the same point.
  • Consider exporting ArrowSchemaUnificationError from ray.data.extensions next to ArrowConversionError, so users who catch the parent by its public name can catch the child by name too.

@ayushk7102 ayushk7102 added the go add ONLY when ready to merge, run all tests label Oct 31, 2026

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

Looks good. The prefix is back, the class is exported, and both transform test files pass on this head. Three small suggestions inline, none blocking.

if flags["has_object"] and flags["has_tensor"]
]
if object_tensor_fields:
raise ValueError(

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.

Suggestion: add a fix hint here. This is the one place that knows the cause, and today the message says what is wrong but not what to do.

Suggested change
raise ValueError(
raise ValueError(
"Found columns with both objects and tensors: "
f"{', '.join(object_tensor_fields)}. "
"Return each of these columns in one form in every batch. Nested "
"Python lists (`ndarray.tolist()`) keep it an object column, and "
"same-shaped ndarrays keep it a tensor column."
)

That is exactly the fix that worked for the user who hit this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good callout. Adding in follow up

Comment on lines +1231 to +1233
for schema in schemas:
for field in schema:
type_counts[field.name][str(field.type)] += 1

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.

Nit: a column that is null in one block shows up under "incompatible types", for example 'pts': object (1 block), tensor (1 block), null (1 block). A null block is compatible with either kind, and with #67579 it becomes null rows of the tensor column. Suggest leaving null out of the counts so the list only names real conflicts.

Suggested change
for schema in schemas:
for field in schema:
type_counts[field.name][str(field.type)] += 1
for schema in schemas:
for field in schema:
if pyarrow.types.is_null(field.type):
# A null column unifies with any type, so it is never a conflict.
continue
type_counts[field.name][str(field.type)] += 1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Discussed, we will land this in the follow up. ON this branch null isn't compatible with a tensor column yet.

Comment on lines +261 to +267
class ArrowSchemaUnificationError(ArrowConversionError):
"""Error raised when block schemas can't be unified into one schema."""

def __init__(self, message: str):
# Skip ArrowConversionError's truncation. The message lists every
# conflicting column and its types, so truncating it hides the cause.
Exception.__init__(self, f"Error converting data to Arrow: {message}")

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.

Nit: the custom __init__ copies the prefix string by hand. The same effect in one line, with the prefix in one place. I checked that this keeps the prefix and skips truncation.

Suggested change
class ArrowSchemaUnificationError(ArrowConversionError):
"""Error raised when block schemas can't be unified into one schema."""
def __init__(self, message: str):
# Skip ArrowConversionError's truncation. The message lists every
# conflicting column and its types, so truncating it hides the cause.
Exception.__init__(self, f"Error converting data to Arrow: {message}")
class ArrowSchemaUnificationError(ArrowConversionError):
"""Error raised when block schemas can't be unified into one schema."""
# The message lists every conflicting column and its types, so it is
# never truncated.
MAX_DATA_STR_LEN = float("inf")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice, thanks!

@goutamvenkat-anyscale
goutamvenkat-anyscale enabled auto-merge (squash) November 3, 2026 01:10
@goutamvenkat-anyscale
goutamvenkat-anyscale merged commit 8e572bf into ray-project:master Nov 3, 2026
7 checks passed
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