pitrou commented on code in PR #39218:
URL: https://github.com/apache/arrow/pull/39218#discussion_r1426698713
##########
python/pyarrow/ipc.pxi:
##########
@@ -883,6 +883,43 @@ cdef class RecordBatchReader(_Weakrefable):
self.reader = c_reader
return self
+ @staticmethod
+ def from_stream(data, schema=None):
+ """
+ Create RecordBatchReader from a Arrow-compatible stream object.
+
+ This accepts objects implementing the Arrow PyCapsule Protocol for
+ streams, i.e. objects that have a ``__arrow_c_stream__`` method.
+
+ Parameters
+ ----------
+ data : Arrow-compatible stream object
+ Any object that implements the Arrow PyCapsule Protocol for
+ streams.
+ schema : Schema, default None
+ The schema to which the stream should be casted, is supported
+ by the stream object.
+
+ Returns
+ -------
+ RecordBatchReader
+ """
+
+ if not hasattr(data, "__arrow_c_stream__"):
+ raise TypeError(
+ "Expected an object implementing the Arrow PyCapsule Protocol
for "
+ "streams (i.e. having a `__arrow_c_stream__` method), "
+ f"got {type(data)!r}."
+ )
+
+ if schema is not None:
+ requested = schema.__arrow_c_schema__()
Review Comment:
Do we also want to first test the presence of this method using `hasattr` as
above?
--
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]