-
Notifications
You must be signed in to change notification settings - Fork 847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Arrow PyCapsule Interface #5070
Changes from 1 commit
b1c43a4
c61d270
6521cba
92b070a
6460701
dfdcfae
5a4f738
8a1a05e
e109c1a
3b95ebc
05ea67d
e7ed58d
dc04b13
86918fa
0e273a3
252e746
60bee4a
46612ce
becda12
2f7767b
1e7bcd3
ae909fb
6f01c91
f183057
107acef
6c44e01
6020247
2e42926
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ | |
//! [pyarrow.Table.to_reader()](https://arrow.apache.org/docs/python/generated/pyarrow.Table.html#pyarrow.Table.to_reader) | ||
//! and then importing the reader as a [ArrowArrayStreamReader]. | ||
|
||
use std::borrow::BorrowMut; | ||
use std::convert::{From, TryFrom}; | ||
use std::ptr::{addr_of, addr_of_mut}; | ||
use std::sync::Arc; | ||
|
@@ -262,9 +263,10 @@ impl FromPyArrow for ArrayData { | |
validate_pycapsule(array_capsule, "arrow_array")?; | ||
|
||
let schema_ptr = unsafe { schema_capsule.reference::<FFI_ArrowSchema>() }; | ||
let array_ptr = unsafe { array_capsule.reference::<FFI_ArrowArray>() }; | ||
let array_ptr = array_capsule.pointer() as *mut FFI_ArrowArray; | ||
let array_mut = unsafe { array_ptr.as_mut() }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW you could use https://doc.rust-lang.org/std/ptr/fn.replace.html as we're already playing with pointers here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated in e7ed58d; is that what you meant? |
||
|
||
let array = std::mem::replace(array_ptr, FFI_ArrowArray::empty()); | ||
let array = std::mem::replace(array_mut.unwrap(), FFI_ArrowArray::empty()); | ||
return ffi::from_ffi(array, schema_ptr).map_err(to_py_err); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential refactor for later, but it would be nice to move the Capsule imports to their own functions that aren't named as if to by PyArrow-specific. Right now this module is named for PyArrow, but the import logic will apply to other Arrow implementations as well.