timsaucer commented on code in PR #825:
URL: https://github.com/apache/datafusion-python/pull/825#discussion_r1730325969


##########
src/dataframe.rs:
##########
@@ -451,6 +458,40 @@ impl PyDataFrame {
         Ok(table)
     }
 
+    fn __arrow_c_stream__<'py>(
+        &'py mut self,
+        py: Python<'py>,
+        requested_schema: Option<Bound<'py, PyCapsule>>,
+    ) -> PyResult<Bound<'py, PyCapsule>> {
+        let mut batches = wait_for_future(py, 
self.df.as_ref().clone().collect())?;
+        let mut schema: Schema = self.df.schema().to_owned().into();
+
+        if let Some(schema_capsule) = requested_schema {
+            validate_pycapsule(&schema_capsule, "arrow_schema")?;
+
+            let schema_ptr = unsafe { 
schema_capsule.reference::<FFI_ArrowSchema>() };
+            let desired_schema = 
Schema::try_from(schema_ptr).map_err(DataFusionError::from)?;
+
+            schema = project_schema(schema, desired_schema)
+                .map_err(|e| DataFusionError::ArrowError(e))?;
+
+            batches = batches
+                .into_iter()
+                .map(|record_batch| record_batch_into_schema(record_batch, 
&schema))
+                .collect::<Result<Vec<RecordBatch>, ArrowError>>()
+                .map_err(|e| DataFusionError::ArrowError(e))?;

Review Comment:
   Right. The collect() line above isn't an implementation of 
`std::iter::Iterator` so we can't just push up the casting into it.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to