This is an automated email from the ASF dual-hosted git repository.
alenka pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 5e6da78a4f ARROW-16652: [Python] Cast compute kernel segfaults when
called with a Table (#14044)
5e6da78a4f is described below
commit 5e6da78a4f696a638ea93cb69ff89a8e070c0105
Author: Kshiteej K <[email protected]>
AuthorDate: Fri Sep 16 13:44:21 2022 +0530
ARROW-16652: [Python] Cast compute kernel segfaults when called with a
Table (#14044)
Repro Script:
```python
import pyarrow as pa
import pyarrow.compute as pc
table = pa.table({'a': [1, 2]})
pc.cast(table, pa.int64())
```
Post PR we get,
```
pyarrow.lib.ArrowInvalid: Tried executing function with non-value type:
Table
```
which is the same error we get if we replace `pc.cast(table, pa.int64())`
with `pc.abs(table)`.
Lead-authored-by: Kshiteej K <[email protected]>
Co-authored-by: kshitij12345 <[email protected]>
Signed-off-by: Alenka Frim <[email protected]>
---
cpp/src/arrow/compute/cast.cc | 4 +++-
python/pyarrow/tests/test_compute.py | 7 +++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/cpp/src/arrow/compute/cast.cc b/cpp/src/arrow/compute/cast.cc
index 52aecf3e45..a57c5e2c79 100644
--- a/cpp/src/arrow/compute/cast.cc
+++ b/cpp/src/arrow/compute/cast.cc
@@ -94,7 +94,9 @@ class CastMetaFunction : public MetaFunction {
const FunctionOptions* options,
ExecContext* ctx) const override {
ARROW_ASSIGN_OR_RAISE(auto cast_options, ValidateOptions(options));
- if (args[0].type()->Equals(*cast_options->to_type)) {
+ // args[0].type() could be a nullptr so check for that before
+ // we do anything with it.
+ if (args[0].type() && args[0].type()->Equals(*cast_options->to_type)) {
return args[0];
}
Result<std::shared_ptr<CastFunction>> result =
diff --git a/python/pyarrow/tests/test_compute.py
b/python/pyarrow/tests/test_compute.py
index f2820b6e25..c41c4fa9b3 100644
--- a/python/pyarrow/tests/test_compute.py
+++ b/python/pyarrow/tests/test_compute.py
@@ -2889,3 +2889,10 @@ def test_expression_call_function():
with pytest.raises(TypeError):
pc.add(1, field)
+
+
+def test_cast_table_raises():
+ table = pa.table({'a': [1, 2]})
+
+ with pytest.raises(pa.lib.ArrowInvalid):
+ pc.cast(table, pa.int64())