Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,15 @@ def _pa_decode_dict_string_array(x: Union[pa.Array, pa.ChunkedArray]) -> Any:
def _to_pa_string_input(x: Any) -> Any:
if isinstance(x, str):
return pa.scalar(x)
elif _is_pa_string_like(x) and isinstance(x, (pa.Array, pa.ChunkedArray)):
x = _pa_decode_dict_string_array(x)
else:
raise
return x
if isinstance(x, (pa.Array, pa.ChunkedArray)) and _is_pa_string_like(x):
return _pa_decode_dict_string_array(x)
actual_type = (
str(x.type) if isinstance(x, (pa.Array, pa.ChunkedArray)) else type(x).__name__
)
raise TypeError(
"Expected string or string-like pyarrow Array/ChunkedArray for string "
f"concatenation, got {actual_type}."
)


def _pa_add_or_concat(left: Any, right: Any) -> Any:
Expand Down
8 changes: 8 additions & 0 deletions python/ray/data/tests/unit/expressions/test_arithmetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import math

import pandas as pd
import pyarrow as pa
import pytest
from pkg_resources import parse_version

Expand Down Expand Up @@ -76,6 +77,13 @@ def test_reverse_addition(self, sample_data):
result.reset_index(drop=True), expected, check_names=False
)

def test_string_concat_invalid_input_type(self):
"""Reject non-string-like inputs in string concatenation."""
table = pa.table({"name": ["a", "b"], "age": [1, 2]})
expr = col("name") + col("age")
with pytest.raises(TypeError, match="string-like pyarrow.*int64"):
eval_expr(expr, table)

# ── Subtraction ──

@pytest.mark.parametrize(
Expand Down