Skip to content

Commit

Permalink
ARROW-8042: [Python] Clean up docstring and error message when creati…
Browse files Browse the repository at this point in the history
…ng ChunkedArray with no chunks

Also uses `ensure_type` in `chunked_array` for usability.

Closes #6573 from wesm/ARROW-8042

Authored-by: Wes McKinney <wesm+git@apache.org>
Signed-off-by: Wes McKinney <wesm+git@apache.org>
  • Loading branch information
wesm committed Mar 11, 2020
1 parent 945400c commit 2fd4892
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions python/pyarrow/table.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import warnings

cdef class ChunkedArray(_PandasConvertible):
"""
Array backed via one or more memory chunks.
An array-like composed from a (possibly empty) collection of pyarrow.Arrays
Warning
-------
Expand Down Expand Up @@ -408,12 +408,13 @@ def chunked_array(arrays, type=None):
c_arrays.push_back(arr.sp_array)

if type:
type = ensure_type(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")
raise ValueError("When passing an empty collection of arrays "
"you must also pass the data type")
sp_chunked_array.reset(new CChunkedArray(c_arrays))

with nogil:
Expand Down
3 changes: 3 additions & 0 deletions python/pyarrow/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ def test_chunked_array_basics():
assert data.to_pylist() == []
data.validate()

data2 = pa.chunked_array([], type='binary')
assert data2.type == pa.binary()

with pytest.raises(ValueError):
pa.chunked_array([])

Expand Down

0 comments on commit 2fd4892

Please sign in to comment.