You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/06/26 20:46:10 UTC

arrow git commit: ARROW-1155: [Python] Add null check when user improperly instantiates ArrayValue instances

Repository: arrow
Updated Branches:
  refs/heads/master bfe15dbf9 -> 3e754a0d0


ARROW-1155: [Python] Add null check when user improperly instantiates ArrayValue instances

Author: Wes McKinney <we...@twosigma.com>

Closes #786 from wesm/ARROW-1155 and squashes the following commits:

e496e919 [Wes McKinney] Add null check when user improperly instantiates ArrayValue instances


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/3e754a0d
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/3e754a0d
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/3e754a0d

Branch: refs/heads/master
Commit: 3e754a0d0b36967f0df7a14135b8be5da3d6cf77
Parents: bfe15db
Author: Wes McKinney <we...@twosigma.com>
Authored: Mon Jun 26 16:46:05 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Mon Jun 26 16:46:05 2017 -0400

----------------------------------------------------------------------
 python/pyarrow/array.pxi             |  7 +++++++
 python/pyarrow/tests/test_scalars.py | 13 +++++++++++++
 2 files changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/3e754a0d/python/pyarrow/array.pxi
----------------------------------------------------------------------
diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi
index c7563c8..2a0b0a7 100644
--- a/python/pyarrow/array.pxi
+++ b/python/pyarrow/array.pxi
@@ -729,7 +729,14 @@ cdef class ArrayValue(Scalar):
     cdef void _set_array(self, const shared_ptr[CArray]& sp_array):
         self.sp_array = sp_array
 
+    def _check_null(self):
+        if self.sp_array.get() == NULL:
+            raise ReferenceError(
+                'ArrayValue instance not propertly initialized '
+                '(references NULL pointer)')
+
     def __repr__(self):
+        self._check_null()
         if hasattr(self, 'as_py'):
             return repr(self.as_py())
         else:

http://git-wip-us.apache.org/repos/asf/arrow/blob/3e754a0d/python/pyarrow/tests/test_scalars.py
----------------------------------------------------------------------
diff --git a/python/pyarrow/tests/test_scalars.py b/python/pyarrow/tests/test_scalars.py
index 149973b..0aa9466 100644
--- a/python/pyarrow/tests/test_scalars.py
+++ b/python/pyarrow/tests/test_scalars.py
@@ -16,6 +16,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import pytest
+
 import pandas as pd
 
 from pyarrow.compat import unittest, u, unicode_type
@@ -28,6 +30,17 @@ class TestScalars(unittest.TestCase):
         with self.assertRaises(Exception):
             pa.NAType()
 
+    def test_ctor_null_check(self):
+        # ARROW-1155
+        with pytest.raises(ReferenceError):
+            repr(pa.Int16Value())
+
+        with pytest.raises(ReferenceError):
+            str(pa.Int16Value())
+
+        with pytest.raises(ReferenceError):
+            repr(pa.StringValue())
+
     def test_bool(self):
         arr = pa.array([True, None, False, None])