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§
Required Methods§
Sourcefn as_ndarray(&self) -> Result<Self::View<'_>, NdarrowError>
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.
Sourceunsafe fn as_ndarray_unchecked(&self) -> Self::View<'_>
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
Sourcefn as_ndarray_masked(&self) -> (Self::View<'_>, Option<&NullBuffer>)
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.