nd-arrow-array
N-dimensional arrays as an Arrow extension type, with NumPy-style kernels.
Each row of an nd_arrow.array column holds one complete array: flat
values, named dimensions and optional attributes. Because it is ordinary
Arrow, the data passes through IPC, Parquet, Flight and DataFusion unchanged.
Struct {
values: List<T>, // flat values, C-order
dim_names: List<Utf8>, // one name per axis
dim_sizes: List<UInt32>, // one size per axis
attrs: Struct { .. }, // optional: one child per attribute key
}
Nulls in values are missing elements. Rank 0 is a scalar.
Concepts
NdArrowArray: one array with namedDimensionsandAttributes.NdColumn: an Arrow column of the extension type.NdRecordBatch: arrays on one shared grid. Each column can use a subset of the dimensions, like an xarrayDataset. Batch-level (global) attributes travel in a reserved__global_attrs__column.
Kernels
nd_arrow_array::compute follows NumPy and xarray semantics. Axes are
addressed by name, and broadcasting aligns axes by name. Reductions skip
nulls, like the NumPy nan* functions. The kernels cover:
- layout (broadcast, transpose, select, concat, pad);
- arithmetic, math and comparisons;
- reductions, scans, sort and search;
- interpolation, rolling windows, group-by and time resampling;
- CF decoding of fill values, packing and time.
Kernels are tested against NumPy reference results.
Example
Create a (time=2, lat=3) array, subtract the mean over time, and keep the
first two latitudes:
use Arc;
use Float64Array;
use ;
use ;
let sst = try_new?
.with_attributes;
let anomaly = ?;
let north = anomaly.isel?;
println!;
<NdArrowArray Float64 (time: 2, lat: 2)>
[[-0.5, -0.5],
[0.5, 0.5]]
Run it with cargo run --example basic.
Python
The nd-arrow-py directory holds the Python package nd-arrow-array
(import nd_arrow_array). Build it with maturin:
Create arrays from NumPy, group them in a record batch and send it to pyarrow:
=
=
=
= # pyarrow.RecordBatch, one row
=
# (2, 3) ndarray
See nd-arrow-py/README.md for details.
Interoperability
- Conversion to and from the Arrow canonical tensor types.
- Conversion to and from
ndarray::ArrayD(featurendarray). - Reductions that merge exactly across chunks.
Features
| Feature | Effect |
|---|---|
parallel |
Runs large kernels with rayon. |
ndarray |
Adds ndarray conversion. |
See FORMAT.md for the format specification, and the crate documentation for the full API.