Skip to content

Commit

Permalink
ARROW-3188: [Python] Table.from_arrays segfaults if lists and schema …
Browse files Browse the repository at this point in the history
…are passed

I've discovered multiple issues in both `Table.from_arrays` and RecordBatch.from_arrays`. This is just a quickfix to prevent the segfault.

Author: Krisztián Szűcs <[email protected]>

Closes apache#2523 from kszucs/ARROW-3188 and squashes the following commits:

24ef5a1 <Krisztián Szűcs> raise TypeError if lists are passed along with schema to Table.from_arrays
  • Loading branch information
kszucs authored and xhochy committed Sep 9, 2018
1 parent 92b6863 commit 462fb00
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions python/pyarrow/table.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ cdef class Table:
columns.reserve(K)

for i in range(K):
if isinstance(arrays[i], (Array, list)):
if isinstance(arrays[i], Array):
columns.push_back(
make_shared[CColumn](
c_schema.get().field(i),
Expand All @@ -1203,7 +1203,7 @@ cdef class Table:
)
)
else:
raise ValueError(type(arrays[i]))
raise TypeError(type(arrays[i]))

return pyarrow_wrap_table(CTable.Make(c_schema, columns))

Expand Down
17 changes: 17 additions & 0 deletions python/pyarrow/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,23 @@ def test_table_from_arrays_invalid_names():
pa.Table.from_arrays(data, names=['a'])


def test_table_from_lists_raises():
data = [
list(range(5)),
[-10, -5, 0, 5, 10]
]

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

schema = pa.schema([
pa.field('a', pa.uint16()),
pa.field('b', pa.int64())
])
with pytest.raises(TypeError):
pa.Table.from_arrays(data, schema=schema)


def test_table_pickle():
data = [
pa.chunked_array([[1, 2], [3, 4]], type=pa.uint32()),
Expand Down

0 comments on commit 462fb00

Please sign in to comment.