jorisvandenbossche commented on code in PR #586:
URL: https://github.com/apache/arrow-nanoarrow/pull/586#discussion_r1755239586


##########
python/src/nanoarrow/array.py:
##########
@@ -542,6 +542,29 @@ def __iter__(self):
             "to iterate over elements of this Array"
         )
 
+    def serialize(self, dst=None) -> Union[bytes, None]:
+        """Write this Array into dst zero or more encapsulated IPC messages

Review Comment:
   ```suggestion
           """Write this Array into dst as zero or more encapsulated IPC 
messages
   ```
   ? (seems some word is missing)



##########
python/src/nanoarrow/array.py:
##########
@@ -542,6 +542,29 @@ def __iter__(self):
             "to iterate over elements of this Array"
         )
 
+    def serialize(self, dst=None) -> Union[bytes, None]:

Review Comment:
   I suppose using `bytes | None` is only allowed if not supporting older 
versions of python?



##########
python/src/nanoarrow/ipc.py:
##########
@@ -236,9 +243,198 @@ def __repr__(self) -> str:
             return f"<{class_label} <invalid>>"
 
 
+class Writer:

Review Comment:
   Also, to understand a bit the different classes here. The already existing 
`Stream` object is essentially the "reader" equivalent?
   
   And for this writer, does that only support the stream format or also the 
file format?



##########
python/src/nanoarrow/ipc.py:
##########
@@ -236,9 +243,198 @@ def __repr__(self) -> str:
             return f"<{class_label} <invalid>>"
 
 
+class Writer:

Review Comment:
   Add a class docstring for Writer?



##########
python/src/nanoarrow/ipc.py:
##########
@@ -236,9 +243,198 @@ def __repr__(self) -> str:
             return f"<{class_label} <invalid>>"
 
 
+class Writer:
+    def __init__(self):
+        self._writer = None
+        self._desc = None
+        self._iterator = None
+
+    def _is_valid(self) -> bool:
+        return self._writer is not None and self._writer.is_valid()
+
+    def __enter__(self):
+        return self
+
+    def __exit__(self, *args, **kwargs):
+        self.close()
+
+    def release(self):
+        """Close stream without writing the end-of-stream marker"""
+        if not self._is_valid():
+            return
+
+        self._writer.release()
+        self._writer = None
+
+    def close(self):
+        """Close stream and write end-of-stream marker"""
+        if not self._is_valid():
+            return
+
+        self._writer.write_end_of_stream()
+        self.release()
+
+    def write_stream(self, obj, schema=None, *, write_schema=None):

Review Comment:
   There could in theory also be a `write_array` (or maybe rather 
`write_batch`) method that takes a single array to write to the stream?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to