pub enum AnyBufferProtocol {
UInt8(PyBuffer<u8>),
UInt16(PyBuffer<u16>),
UInt32(PyBuffer<u32>),
UInt64(PyBuffer<u64>),
Int8(PyBuffer<i8>),
Int16(PyBuffer<i16>),
Int32(PyBuffer<i32>),
Int64(PyBuffer<i64>),
Float32(PyBuffer<f32>),
Float64(PyBuffer<f64>),
}
Expand description
An enum over buffer protocol input types.
Variants§
UInt8(PyBuffer<u8>)
UInt16(PyBuffer<u16>)
UInt32(PyBuffer<u32>)
UInt64(PyBuffer<u64>)
Int8(PyBuffer<i8>)
Int16(PyBuffer<i16>)
Int32(PyBuffer<i32>)
Int64(PyBuffer<i64>)
Float32(PyBuffer<f32>)
Float64(PyBuffer<f64>)
Implementations§
Source§impl AnyBufferProtocol
impl AnyBufferProtocol
Sourcepub fn into_arrow_array(self) -> PyArrowResult<ArrayRef>
pub fn into_arrow_array(self) -> PyArrowResult<ArrayRef>
Consume this and convert to an Arrow ArrayRef
.
For almost all buffer protocol objects this is zero-copy. Only boolean-typed buffers need to be copied, because boolean Python buffers are one byte per element, while Arrow buffers are one bit per element. All numeric buffers are zero-copy compatible.
This uses Buffer::from_custom_allocation
, which creates Arrow buffers from existing
memory regions. The Buffer
tracks ownership of the PyBuffer
memory via reference
counting. The PyBuffer
’s release callback will be called when the Arrow Buffer
sees
that the PyBuffer
’s reference count
reaches zero.
§Safety
- This assumes that the Python buffer is immutable. Immutability is not guaranteed by the Python buffer protocol, so the end user must uphold this. Mutating a Python buffer could lead to undefined behavior.
Sourcepub fn into_arrow_buffer(self) -> PyArrowResult<Buffer>
pub fn into_arrow_buffer(self) -> PyArrowResult<Buffer>
Consume this buffer protocol object and convert to an Arrow Buffer.
Trait Implementations§
Source§impl Debug for AnyBufferProtocol
impl Debug for AnyBufferProtocol
Source§impl<'py> FromPyObject<'py> for AnyBufferProtocol
impl<'py> FromPyObject<'py> for AnyBufferProtocol
Source§impl TryFrom<AnyBufferProtocol> for PyArray
impl TryFrom<AnyBufferProtocol> for PyArray
Source§type Error = PyArrowError
type Error = PyArrowError
The type returned in the event of a conversion error.
Auto Trait Implementations§
impl Freeze for AnyBufferProtocol
impl RefUnwindSafe for AnyBufferProtocol
impl Send for AnyBufferProtocol
impl Sync for AnyBufferProtocol
impl Unpin for AnyBufferProtocol
impl UnwindSafe for AnyBufferProtocol
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more