AnyBufferProtocol

Enum AnyBufferProtocol 

Source
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

Source

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

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'py> FromPyObject<'py> for AnyBufferProtocol

Source§

fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult<Self>

Extracts Self from the bound smart pointer obj. Read more
Source§

impl TryFrom<AnyBufferProtocol> for PyArray

Source§

type Error = PyArrowError

The type returned in the event of a conversion error.
Source§

fn try_from(value: AnyBufferProtocol) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'py, T> FromPyObjectBound<'_, 'py> for T
where T: FromPyObject<'py>,

Source§

fn from_py_object_bound(ob: Borrowed<'_, 'py, PyAny>) -> Result<T, PyErr>

Extracts Self from the bound smart pointer obj. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Ungil for T
where T: Send,