timsaucer commented on code in PR #10894:
URL: https://github.com/apache/arrow-rs/pull/10894#discussion_r4106734251


##########
arrow-pyarrow/src/lib.rs:
##########
@@ -403,63 +434,73 @@ impl<T: ToPyArrow> ToPyArrow for Vec<T> {
     }
 }
 
+fn record_batch_from_pyarrow_bound_impl(
+    value: &Bound<PyAny>,
+    array_data_from_pyarrow: impl Fn(&Bound<PyAny>) -> PyResult<ArrayData>,
+) -> PyResult<RecordBatch> {
+    // Newer versions of PyArrow as well as other libraries with Arrow data 
implement this
+    // method, so prefer it over _export_to_c.
+    // See 
https://arrow.apache.org/docs/format/CDataInterface/PyCapsuleInterface.html
+    if let Some((schema_capsule, array_capsule)) = 
call_arrow_c_array_method_if_exists(value)? {
+        let schema_ptr = extract_capsule(&schema_capsule, c"arrow_schema", 
"__arrow_c_array__")?;
+        let array_ptr = extract_capsule(&array_capsule, c"arrow_array", 
"__arrow_c_array__")?;
+        let ffi_array = unsafe { FFI_ArrowArray::from_raw(array_ptr.as_ptr()) 
};
+        let array_data =

Review Comment:
   If we want this to have a safe path, then I think after this `ffi::from_ffi` 
we will need a `array_data.validate_full()`. We would probably need to pass in 
something like `validate:bool` for the function arguments to enable the check.



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