This is an automated email from the ASF dual-hosted git repository.
wesm 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 6b80fa8 ARROW-2693: [Python] pa.chunked_array causes a segmentation
fault on empty input
6b80fa8 is described below
commit 6b80fa824ed6b621122eb17f46106936fa72dd4b
Author: Korn, Uwe <[email protected]>
AuthorDate: Tue Jun 12 00:18:15 2018 -0400
ARROW-2693: [Python] pa.chunked_array causes a segmentation fault on empty
input
Author: Korn, Uwe <[email protected]>
Closes #2128 from xhochy/ARROW-2693 and squashes the following commits:
922b71b3 <Korn, Uwe> ARROW-2693: pa.chunked_array causes a segmentation
fault on empty input
---
python/pyarrow/includes/libarrow.pxd | 2 ++
python/pyarrow/table.pxi | 10 +++++++++-
python/pyarrow/tests/test_table.py | 8 ++++++++
3 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/python/pyarrow/includes/libarrow.pxd
b/python/pyarrow/includes/libarrow.pxd
index defb91d..a6188b6 100644
--- a/python/pyarrow/includes/libarrow.pxd
+++ b/python/pyarrow/includes/libarrow.pxd
@@ -428,6 +428,8 @@ cdef extern from "arrow/api.h" namespace "arrow" nogil:
cdef cppclass CChunkedArray" arrow::ChunkedArray":
CChunkedArray(const vector[shared_ptr[CArray]]& arrays)
+ CChunkedArray(const vector[shared_ptr[CArray]]& arrays,
+ const shared_ptr[CDataType]& type)
int64_t length()
int64_t null_count()
int num_chunks()
diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi
index 96ed55b..6e64d32 100644
--- a/python/pyarrow/table.pxi
+++ b/python/pyarrow/table.pxi
@@ -191,6 +191,7 @@ def chunked_array(arrays, type=None):
Array arr
vector[shared_ptr[CArray]] c_arrays
shared_ptr[CChunkedArray] sp_chunked_array
+ shared_ptr[CDataType] sp_data_type
for x in arrays:
if isinstance(x, Array):
@@ -202,7 +203,14 @@ def chunked_array(arrays, type=None):
c_arrays.push_back(arr.sp_array)
- sp_chunked_array.reset(new CChunkedArray(c_arrays))
+ if type:
+ sp_data_type = pyarrow_unwrap_data_type(type)
+ sp_chunked_array.reset(new CChunkedArray(c_arrays, sp_data_type))
+ else:
+ if c_arrays.size() == 0:
+ raise ValueError("Cannot construct a chunked array with neither "
+ "arrays nor type")
+ sp_chunked_array.reset(new CChunkedArray(c_arrays))
return pyarrow_wrap_chunked_array(sp_chunked_array)
diff --git a/python/pyarrow/tests/test_table.py
b/python/pyarrow/tests/test_table.py
index 634a179..1df57bd 100644
--- a/python/pyarrow/tests/test_table.py
+++ b/python/pyarrow/tests/test_table.py
@@ -24,6 +24,14 @@ import pytest
import pyarrow as pa
+def test_chunked_array_basics():
+ data = pa.chunked_array([], type=pa.string())
+ assert data.to_pylist() == []
+
+ with pytest.raises(ValueError):
+ pa.chunked_array([])
+
+
def test_chunked_array_getitem():
data = [
pa.array([1, 2, 3]),
--
To stop receiving notification emails like this one, please contact
[email protected].