You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by uw...@apache.org on 2018/09/09 10:31:12 UTC

[arrow] branch master updated: ARROW-3188: [Python] Table.from_arrays segfaults if lists and schema are passed

This is an automated email from the ASF dual-hosted git repository.

uwe 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 462fb00  ARROW-3188: [Python] Table.from_arrays segfaults if lists and schema are passed
462fb00 is described below

commit 462fb00cfd04be403ead05fee40952b14cd13e8e
Author: Krisztián Szűcs <sz...@gmail.com>
AuthorDate: Sun Sep 9 12:31:00 2018 +0200

    ARROW-3188: [Python] Table.from_arrays segfaults if lists and schema 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 <sz...@gmail.com>
    
    Closes #2523 from kszucs/ARROW-3188 and squashes the following commits:
    
    24ef5a19 <Krisztián Szűcs> raise TypeError if lists are passed along with schema to Table.from_arrays
---
 python/pyarrow/table.pxi           |  4 ++--
 python/pyarrow/tests/test_table.py | 17 +++++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi
index 4780eff..bbf40e0 100644
--- a/python/pyarrow/table.pxi
+++ b/python/pyarrow/table.pxi
@@ -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),
@@ -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))
 
diff --git a/python/pyarrow/tests/test_table.py b/python/pyarrow/tests/test_table.py
index b58a1de..14609ad 100644
--- a/python/pyarrow/tests/test_table.py
+++ b/python/pyarrow/tests/test_table.py
@@ -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()),