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
5 changes: 4 additions & 1 deletion python/pyarrow/table.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ cdef int _schema_from_arrays(

fields.resize(K)

if len(arrays) == 0:
if not K:
raise ValueError('Must pass at least one array')

if isinstance(arrays[0], Column):
Expand All @@ -328,6 +328,9 @@ cdef int _schema_from_arrays(
if names is None:
raise ValueError('Must pass names when constructing '
'from Array objects')
if len(names) != K:
raise ValueError("Length of names ({}) does not match "
"length of arrays ({})".format(len(names), K))
for i in range(K):
val = arrays[i]
if isinstance(val, (Array, ChunkedArray)):
Expand Down
2 changes: 1 addition & 1 deletion python/pyarrow/tests/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_single_pylist_column_roundtrip(tmpdir):
filename = tmpdir.join('single_{}_column.parquet'
.format(dtype.__name__))
data = [pa.array(list(map(dtype, range(5))))]
table = pa.Table.from_arrays(data, names=('a', 'b'))
table = pa.Table.from_arrays(data, names=['a'])
_write_table(table, filename.strpath)
table_read = _read_table(filename.strpath)
for col_written, col_read in zip(table.itercolumns(),
Expand Down
24 changes: 24 additions & 0 deletions python/pyarrow/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ def test_recordbatch_basics():
batch[2]


def test_recordbatch_from_arrays_invalid_names():
data = [
pa.array(range(5)),
pa.array([-10, -5, 0, 5, 10])
]
with pytest.raises(ValueError):
pa.RecordBatch.from_arrays(data, names=['a', 'b', 'c'])

with pytest.raises(ValueError):
pa.RecordBatch.from_arrays(data, names=['a'])


def test_recordbatch_empty_metadata():
data = [
pa.array(range(5)),
Expand Down Expand Up @@ -200,6 +212,18 @@ def test_table_basics():
assert chunk is not None


def test_table_from_arrays_invalid_names():
data = [
pa.array(range(5)),
pa.array([-10, -5, 0, 5, 10])
]
with pytest.raises(ValueError):
pa.Table.from_arrays(data, names=['a', 'b', 'c'])

with pytest.raises(ValueError):
pa.Table.from_arrays(data, names=['a'])


def test_table_add_column():
data = [
pa.array(range(5)),
Expand Down