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 2018/08/14 04:11:38 UTC

[arrow] branch master updated: ARROW-3045: [Python] Remove nullcheck from ipc Message and MessageReader

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

wesm 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 b99d8f3  ARROW-3045: [Python] Remove nullcheck from ipc Message and MessageReader
b99d8f3 is described below

commit b99d8f391b455af64182937354024bea2c09fa69
Author: Krisztián Szűcs <sz...@gmail.com>
AuthorDate: Tue Aug 14 00:10:54 2018 -0400

    ARROW-3045: [Python] Remove nullcheck from ipc Message and MessageReader
    
    Author: Krisztián Szűcs <sz...@gmail.com>
    
    Closes #2425 from kszucs/ARROW-3045 and squashes the following commits:
    
    9692aeea <Krisztián Szűcs> remove nullcheck from ipc Message and MessageReader
---
 python/pyarrow/ipc.pxi            | 27 +++++++++++----------------
 python/pyarrow/tests/test_misc.py |  4 +++-
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/python/pyarrow/ipc.pxi b/python/pyarrow/ipc.pxi
index 2f51142..7ab827e 100644
--- a/python/pyarrow/ipc.pxi
+++ b/python/pyarrow/ipc.pxi
@@ -25,26 +25,24 @@ cdef class Message:
     def __cinit__(self):
         pass
 
-    def __null_check(self):
-        if self.message.get() == NULL:
-            raise TypeError('Message improperly initialized (null)')
+    def __init__(self):
+        raise TypeError("Do not call {}'s constructor directly, use "
+                        "`pyarrow.ipc.read_message` function instead."
+                        .format(self.__class__.__name__))
 
     property type:
 
         def __get__(self):
-            self.__null_check()
             return frombytes(FormatMessageType(self.message.get().type()))
 
     property metadata:
 
         def __get__(self):
-            self.__null_check()
             return pyarrow_wrap_buffer(self.message.get().metadata())
 
     property body:
 
         def __get__(self):
-            self.__null_check()
             cdef shared_ptr[CBuffer] body = self.message.get().body()
             if body.get() == NULL:
                 return None
@@ -113,17 +111,14 @@ cdef class MessageReader:
     def __cinit__(self):
         pass
 
-    def __null_check(self):
-        if self.reader.get() == NULL:
-            raise TypeError('Message improperly initialized (null)')
-
-    def __repr__(self):
-        self.__null_check()
-        return object.__repr__(self)
+    def __init__(self):
+        raise TypeError("Do not call {}'s constructor directly, use "
+                        "`pyarrow.ipc.MessageReader.open_stream` function "
+                        "instead.".format(self.__class__.__name__))
 
     @staticmethod
     def open_stream(source):
-        cdef MessageReader result = MessageReader()
+        cdef MessageReader result = MessageReader.__new__(MessageReader)
         cdef shared_ptr[InputStream] in_stream
         cdef unique_ptr[CMessageReader] reader
         get_input_stream(source, &in_stream)
@@ -142,7 +137,7 @@ cdef class MessageReader:
         Read next Message from the stream. Raises StopIteration at end of
         stream
         """
-        cdef Message result = Message()
+        cdef Message result = Message.__new__(Message)
 
         with nogil:
             check_status(self.reader.get().ReadNextMessage(&result.message))
@@ -490,7 +485,7 @@ def read_message(source):
     message : Message
     """
     cdef:
-        Message result = Message()
+        Message result = Message.__new__(Message)
         NativeFile cpp_file
 
     if not isinstance(source, NativeFile):
diff --git a/python/pyarrow/tests/test_misc.py b/python/pyarrow/tests/test_misc.py
index 26717e1..1c20614 100644
--- a/python/pyarrow/tests/test_misc.py
+++ b/python/pyarrow/tests/test_misc.py
@@ -107,7 +107,9 @@ def test_cpu_count():
     pa.ListValue,
     pa.UnionValue,
     pa.StructValue,
-    pa.DictionaryValue
+    pa.DictionaryValue,
+    pa.ipc.Message,
+    pa.ipc.MessageReader
 ])
 def test_extension_type_constructor_errors(klass):
     # ARROW-2638: prevent calling extension class constructors directly