Skip to main content

nd_arrow_array/
lib.rs

1//! N-dimensional arrays as an Arrow extension type.
2//!
3//! - [`NdArrowArray`]: one N-dimensional array: flat values, named
4//!   [`Dimensions`] and [`Attributes`].
5//! - [`NdArrayType`]: the `nd_arrow.array` Arrow extension type. Its storage
6//!   is `Struct { values, dim_names, dim_sizes, attrs }`.
7//! - [`NdColumn`]: an Arrow column of the extension type. Each row is one
8//!   [`NdArrowArray`].
9//! - [`NdRecordBatch`]: nd arrays over a shared target grid, encoded as a
10//!   [`RecordBatch`](arrow::record_batch::RecordBatch) of nd columns.
11//! - [`compute`]: kernels with NumPy and xarray semantics (layout,
12//!   arithmetic, reductions, search, interpolation, CF decoding).
13//! - [`tensor`]: conversion to and from the Arrow canonical tensor types.
14//!
15//! Features: `parallel` runs large gathers and reductions with rayon;
16//! `ndarray` adds conversion to and from `ndarray::ArrayD`.
17//!
18//! # Example
19//!
20//! ```
21//! use std::sync::Arc;
22//!
23//! use arrow::array::Float64Array;
24//! use nd_arrow_array::compute::{Selector, Slice};
25//! use nd_arrow_array::{Attributes, Dimensions, NdArrowArray, NdColumn};
26//!
27//! # fn main() -> nd_arrow_array::Result<()> {
28//! let sst = NdArrowArray::try_new(
29//!     Arc::new(Float64Array::from(vec![10.0, 11.0, 12.0, 14.0, 15.0, 16.0])),
30//!     Dimensions::try_new([("time", 2), ("lat", 3)])?,
31//! )?
32//! .with_attributes(Attributes::new().with("units", "degC"));
33//!
34//! // Anomaly against the time mean: the mean broadcasts back by name.
35//! let anomaly = (&sst - &sst.mean(Some(&["time"]))?)?;
36//! let north = anomaly.isel(&[("lat", Selector::Slice(Slice::range(1, 3)))])?;
37//! assert_eq!(north.shape(), vec![2, 2]);
38//! println!("{north}");
39//!
40//! // One row of an Arrow column with the `nd_arrow.array` extension type.
41//! let column = NdColumn::try_from_arrays([&sst])?;
42//! assert_eq!(column.value(0), sst);
43//! # Ok(())
44//! # }
45//! ```
46
47#![warn(missing_docs)]
48
49pub mod array;
50pub mod attributes;
51pub mod batch;
52pub mod column;
53pub mod compute;
54pub mod dimensions;
55mod display;
56pub mod error;
57pub mod extension;
58#[cfg(feature = "ndarray")]
59mod ndarray_interop;
60pub mod tensor;
61
62pub use array::NdArrowArray;
63pub use attributes::{Attributes, IntoScalar};
64pub use batch::{NdRecordBatch, encode_batches, infer_target};
65pub use column::{NdColumn, NdColumnBuilder};
66pub use dimensions::{Dimension, Dimensions};
67pub use error::{NdError, Result};
68pub use extension::{NdArrayMetadata, NdArrayType};