You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/09 11:22:07 UTC

[GitHub] [arrow] pitrou commented on a diff in pull request #14583: ARROW-18229: [Python] Check schema argument type in RecordBatchReader.from_batches

pitrou commented on code in PR #14583:
URL: https://github.com/apache/arrow/pull/14583#discussion_r1017809161


##########
python/pyarrow/tests/test_ipc.py:
##########
@@ -1153,9 +1153,17 @@ def make_batches():
     batches = iter(UserList(make_batches()))  # weakrefable
     wr = weakref.ref(batches)
 
-    with pa.ipc.RecordBatchReader.from_batches(make_schema(),
-                                               batches) as reader:
+    with pa.RecordBatchReader.from_batches(make_schema(),
+                                           batches) as reader:
         batches = None
         assert wr() is not None
         assert list(reader) == make_batches()
         assert wr() is None
+
+    # ensure we get proper error when not passing a schema
+    # (https://issues.apache.org/jira/browse/ARROW-18229)
+    batches = make_batches()
+    with pytest.raises(TypeError):
+        reader = pa.RecordBatchReader.from_batches(
+            [('field', pa.int64())], batches)

Review Comment:
   TBH, it would be nice if the list of fields was implicitly converted into a schema here :-)



##########
python/pyarrow/tests/test_ipc.py:
##########
@@ -1153,9 +1153,17 @@ def make_batches():
     batches = iter(UserList(make_batches()))  # weakrefable
     wr = weakref.ref(batches)
 
-    with pa.ipc.RecordBatchReader.from_batches(make_schema(),
-                                               batches) as reader:
+    with pa.RecordBatchReader.from_batches(make_schema(),
+                                           batches) as reader:
         batches = None
         assert wr() is not None
         assert list(reader) == make_batches()
         assert wr() is None
+
+    # ensure we get proper error when not passing a schema
+    # (https://issues.apache.org/jira/browse/ARROW-18229)
+    batches = make_batches()
+    with pytest.raises(TypeError):
+        reader = pa.RecordBatchReader.from_batches(
+            [('field', pa.int64())], batches)
+        str(reader.schema)

Review Comment:
   Why the `str` call? Which line is failing with a `TypeError`?



##########
python/pyarrow/ipc.pxi:
##########
@@ -757,7 +757,7 @@ cdef class RecordBatchReader(_Weakrefable):
         return self
 
     @staticmethod
-    def from_batches(schema, batches):
+    def from_batches(Schema schema, batches):

Review Comment:
   I don't think this protects `schema` from being None, though?



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org