Skip to content

Commit

Permalink
Correct Append step for null scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
AlenkaF committed Jun 22, 2023
1 parent 534579f commit 0263be5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion python/pyarrow/src/arrow/python/python_to_arrow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,14 @@ class PyPrimitiveConverter<T, enable_if_null<T>>
if (PyValue::IsNull(this->options_, value)) {
return this->primitive_builder_->AppendNull();
} else if (arrow::py::is_scalar(value)) {
return this->primitive_builder_->AppendNull();
ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Scalar> scalar,
arrow::py::unwrap_scalar(value));
if (scalar->is_valid) {
return Status::Invalid("Cannot append scalar of type ", scalar->type->ToString(),
" to builder for type null");
} else {
return this->primitive_builder_->AppendNull();
}
} else {
ARROW_ASSIGN_OR_RAISE(
auto converted, PyValue::Convert(this->primitive_type_, this->options_, value));
Expand Down
7 changes: 6 additions & 1 deletion python/pyarrow/tests/test_convert_builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2437,7 +2437,7 @@ def test_array_accepts_pyarrow_scalar_with_type(seq, data, scalar_data, value_ty
assert expect.equals(result)


def test_array_accepts_pyarrow_scalar_something():
def test_array_accepts_pyarrow_scalar_from_compute():
arr = pa.array([1, 2, 3])
result = pa.array([arr.sum()])
expect = pa.array([6])
Expand Down Expand Up @@ -2473,3 +2473,8 @@ def test_array_accepts_pyarrow_scalar_errors(seq):
match="Cannot append scalar of type string "
"to builder for type int32"):
pa.array([pa.scalar("a")], type=pa.int32())

with pytest.raises(pa.ArrowInvalid,
match="Cannot append scalar of type int64 "
"to builder for type null"):
pa.array([pa.scalar(1)], type=pa.null())

0 comments on commit 0263be5

Please sign in to comment.