Skip to main content

AsNdarray

Trait AsNdarray 

Source
pub trait AsNdarray {
    type View<'a>
       where Self: 'a;

    // Required methods
    fn as_ndarray(&self) -> Result<Self::View<'_>, NdarrowError>;
    unsafe fn as_ndarray_unchecked(&self) -> Self::View<'_>;
    fn as_ndarray_masked(&self) -> (Self::View<'_>, Option<&NullBuffer>);
}
Expand description

Zero-copy conversion from an Arrow array to an ndarray view.

Implementations borrow the Arrow buffer and produce ndarray views. No allocation occurs on the bridge path.

§Does not allocate

All methods produce views (borrowed data). The view’s lifetime is tied to the Arrow array’s lifetime.

Required Associated Types§

Source

type View<'a> where Self: 'a

The ndarray view type produced by this conversion.

Required Methods§

Source

fn as_ndarray(&self) -> Result<Self::View<'_>, NdarrowError>

Zero-copy conversion to an ndarray view.

Returns Err(NdarrowError::NullsPresent) if the array contains any null values. The null check is O(1) — it reads the pre-computed null count, not the data.

§Does not allocate
§Errors

Returns NdarrowError::NullsPresent when the array contains nulls.

Source

unsafe fn as_ndarray_unchecked(&self) -> Self::View<'_>

Zero-copy conversion to an ndarray view without null checking.

§Safety

The caller must guarantee that the array contains no null values. Accessing data at null positions through the returned view is undefined behavior (the underlying buffer may contain arbitrary bytes at those positions).

In debug builds, this asserts null_count() == 0.

§Does not allocate
Source

fn as_ndarray_masked(&self) -> (Self::View<'_>, Option<&NullBuffer>)

Zero-copy conversion to an ndarray view with a validity bitmap.

Always succeeds. Returns the view alongside the optional null buffer. If null_count() == 0, the null buffer is None.

The caller decides how to handle nulls using the bitmap.

§Does not allocate

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> AsNdarray for PrimitiveArray<T>

Source§

type View<'a> = ArrayBase<ViewRepr<&'a <T as ArrowPrimitiveType>::Native>, Dim<[usize; 1]>>

Source§

fn as_ndarray(&self) -> Result<Self::View<'_>, NdarrowError>

Source§

unsafe fn as_ndarray_unchecked(&self) -> Self::View<'_>

Source§

fn as_ndarray_masked(&self) -> (Self::View<'_>, Option<&NullBuffer>)

Implementors§