Skip to content
Closed
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
2 changes: 2 additions & 0 deletions python/pyarrow/includes/libarrow.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 9 additions & 1 deletion python/pyarrow/table.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)


Expand Down
8 changes: 8 additions & 0 deletions python/pyarrow/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
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]),
Expand Down