Expand description
§ndarrow
Zero-copy bridge between Apache Arrow and ndarray.
ndarrow lets you move data between Arrow and ndarray with zero allocations on the bridge path:
- Arrow → ndarray: borrow Arrow buffers as ndarray views (O(1), no copy)
- ndarray → Arrow: transfer owned ndarray buffers into Arrow arrays (O(1), ownership move)
§Quick Example
use arrow_array::Float64Array;
use ndarrow::{AsNdarray, IntoArrow};
use ndarray::Array1;
// Arrow -> ndarray (zero-copy view)
let arrow_array = Float64Array::from(vec![1.0, 2.0, 3.0, 4.0]);
let view = arrow_array.as_ndarray().unwrap(); // ArrayView1<f64>, no allocation
assert_eq!(view[0], 1.0);
// ndarray -> Arrow (zero-copy ownership transfer)
let result = Array1::from_vec(vec![5.0, 6.0, 7.0, 8.0]);
let arrow_result: Float64Array = result.into_arrow().unwrap();
assert_eq!(arrow_result.len(), 4);§Null Handling
Null semantics are explicit at the call site:
use arrow_array::Float64Array;
use ndarrow::AsNdarray;
let array = Float64Array::from(vec![1.0, 2.0, 3.0]);
// Validated: returns Err if nulls present (O(1) check)
let view = array.as_ndarray().unwrap();
// Unchecked: caller guarantees no nulls (zero cost)
let view = unsafe { array.as_ndarray_unchecked() };
// Masked: returns view + validity bitmap (zero allocation)
let (view, mask) = array.as_ndarray_masked();§Performance Guarantee
Bridge conversions are O(1) regardless of array size. The bridge creates views (pointer + shape) or transfers buffer ownership. It never touches the data.
Re-exports§
pub use complex::Complex32Extension;pub use complex::Complex64Extension;pub use complex::array1_complex32_to_extension;pub use complex::array1_complex64_to_extension;pub use complex::complex32_as_array_view1;pub use complex::complex64_as_array_view1;pub use element::NdarrowElement;pub use error::NdarrowError;pub use extensions::RegisteredExtension;pub use extensions::deserialize_registered_extension;pub use extensions::registered_extension_names;pub use inbound::AsNdarray;pub use inbound::fixed_size_list_as_array2;pub use inbound::fixed_size_list_as_array2_masked;pub use inbound::fixed_size_list_as_array2_unchecked;pub use outbound::IntoArrow;pub use sparse::CsrMatrixExtension;pub use sparse::CsrMatrixMetadata;pub use sparse::CsrView;pub use sparse::csr_to_extension_array;pub use sparse::csr_view_from_columns;pub use sparse::csr_view_from_extension;pub use tensor::VariableShapeTensorIter;pub use tensor::arrayd_to_fixed_shape_tensor;pub use tensor::arrays_to_variable_shape_tensor;pub use tensor::fixed_shape_tensor_as_array_viewd;pub use tensor::variable_shape_tensor_iter;
Modules§
- complex
- Complex-valued Arrow/ndarray bridge utilities.
- element
- Element type bridge between Arrow primitive types and ndarray element types.
- error
- Error types for ndarrow conversions.
- extensions
- Extension type registration and deserialization utilities.
- helpers
- Explicit helper APIs that may allocate.
- inbound
- Arrow to ndarray conversions (zero-copy views).
- outbound
- ndarray to Arrow conversions (zero-copy ownership transfer).
- prelude
- ndarrow prelude.
- sparse
- Sparse Arrow/ndarray bridge utilities.
- tensor
- Tensor Arrow/ndarray bridge utilities.