Tpt commented on code in PR #9639:
URL: https://github.com/apache/arrow-rs/pull/9639#discussion_r3024194535
##########
arrow-pyarrow/src/lib.rs:
##########
@@ -149,6 +149,24 @@ fn validate_pycapsule(capsule: &Bound<PyCapsule>, name:
&str) -> PyResult<()> {
Ok(())
}
+fn extract_arrow_c_array_capsules<'py>(
+ value: &Bound<'py, PyAny>,
+) -> PyResult<(Bound<'py, PyCapsule>, Bound<'py, PyCapsule>)> {
+ let tuple = value.call_method0("__arrow_c_array__")?;
+
+ if !tuple.is_instance_of::<PyTuple>() {
+ return Err(PyTypeError::new_err(
+ "Expected __arrow_c_array__ to return a tuple of (schema, array)
capsules.",
+ ));
+ }
+
+ tuple.extract().map_err(|_| {
Review Comment:
tip if you want to propagate the original error as a "cause" to get a
sightly nicer backtrace:
```suggestion
tuple.extract().map_err(|e| {
let err = PyTypeError::new_err(
"Expected __arrow_c_array__ to return a tuple of (schema, array)
capsules.",
);
err.set_cause(value.py(), Some(e));
err
```
```
##########
arrow-pyarrow/src/lib.rs:
##########
@@ -149,6 +149,24 @@ fn validate_pycapsule(capsule: &Bound<PyCapsule>, name:
&str) -> PyResult<()> {
Ok(())
}
+fn extract_arrow_c_array_capsules<'py>(
+ value: &Bound<'py, PyAny>,
+) -> PyResult<(Bound<'py, PyCapsule>, Bound<'py, PyCapsule>)> {
+ let tuple = value.call_method0("__arrow_c_array__")?;
+
+ if !tuple.is_instance_of::<PyTuple>() {
Review Comment:
if I am not mistaken `.extract()` will fail if `tuple` is not a tuple,
returning the exact same error. I think we can drop this case.
--
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]