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/04/23 20:53:30 UTC

[arrow] branch master updated: ARROW-2492: [Python] Prevent segfault on accidental call of pyarrow.Array

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 7545e3e  ARROW-2492: [Python] Prevent segfault on accidental call of pyarrow.Array
7545e3e is described below

commit 7545e3e4c65904dddf02036977be819b96b994ea
Author: Korn, Uwe <Uw...@blue-yonder.com>
AuthorDate: Mon Apr 23 22:53:23 2018 +0200

    ARROW-2492: [Python] Prevent segfault on accidental call of pyarrow.Array
    
    Author: Korn, Uwe <Uw...@blue-yonder.com>
    
    Closes #1926 from xhochy/ARROW-2492 and squashes the following commits:
    
    95d59ad1 <Korn, Uwe> ARROW-2492:  Prevent segfault on accidental call of pyarrow.Array
---
 python/pyarrow/array.pxi           | 12 ++++++++++++
 python/pyarrow/tests/test_array.py |  6 ++++++
 2 files changed, 18 insertions(+)

diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi
index 7193afe..32ea77f 100644
--- a/python/pyarrow/array.pxi
+++ b/python/pyarrow/array.pxi
@@ -283,6 +283,18 @@ cdef _append_array_buffers(const CArrayData* ad, list res):
 
 cdef class Array:
 
+    def __init__(self, *args, **kwargs):
+        """
+        Do not call this constructor directly, use factories
+        like ``pyarrow.array``.
+        """
+        # Check if the constructor was called with arguments.
+        # This was probably by accident from a user. Instead of segfaulting
+        # we should provide them with a meaningful error.
+        if len(args) > 0 or len(kwargs) > 0:
+            raise RuntimeError("Don't call pyarrow.Array directly, use "
+                               "pyarrow.array instead")
+
     cdef void init(self, const shared_ptr[CArray]& sp_array):
         self.sp_array = sp_array
         self.ap = sp_array.get()
diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py
index f4602b6..7ed2cc9 100644
--- a/python/pyarrow/tests/test_array.py
+++ b/python/pyarrow/tests/test_array.py
@@ -43,6 +43,12 @@ def test_getitem_NA():
     assert arr[1] is pa.NA
 
 
+def test_constructor_raises():
+    # This could happen by wrong capitalization.
+    with pytest.raises(RuntimeError):
+        pa.Array([1, 2])
+
+
 def test_list_format():
     arr = pa.array([[1], None, [2, 3, None]])
     result = fmt.array_format(arr)

-- 
To stop receiving notification emails like this one, please contact
uwe@apache.org.