Repository navigation
[Data] Log the conflicting column and types on schema unification error - #67647
goutamvenkat-anyscale merged 4 commits into
Conversation
Signed-off-by: Ayush Kumar <[email protected]>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
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
ArrowSchemaUnificationErrorfromray.data.extensionsnext toArrowConversionError, so users who catch the parent by its public name can catch the child by name too.
…en test? Signed-off-by: Ayush Kumar <[email protected]>
marwan116
left a comment
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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.
| 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.
There was a problem hiding this comment.
Good callout. Adding in follow up
| for schema in schemas: | ||
| for field in schema: | ||
| type_counts[field.name][str(field.type)] += 1 |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
Discussed, we will land this in the follow up. ON this branch null isn't compatible with a tensor column yet.
| 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}") |
There was a problem hiding this comment.
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.
| 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") |
Signed-off-by: Ayush Kumar <[email protected]>
… truncation Signed-off-by: Ayush Kumar <[email protected]>
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
ArrowConversionErrortruncates its message to 200 characters, so the raw schema dump stops after the first schema and the conflicting tensor type never appears._reconcile_diverging_fieldsraises on the first conflicting column, so other conflicting columns go unreported.pa.Schemashows extension types asextension<ray.data.arrow_tensor_v2<...>>, without shape or dtype.After
concatraises the newArrowSchemaUnificationError, a subclass ofArrowConversionErrorthat skips the truncation. Existingexcept ArrowConversionErrorhandlers (e.g. the pandas fallback inblock.py) still catch it.str()(tensor shape and dtype included) and how many blocks had it.ValueErrornow names all conflicting columns, not just the first.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
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.Failed to unify schemasandFound columns with both objects and tensorsstill pass.Noneacross 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.