use crate::dtype::{DType, FloatKind, IntKind};
use crate::formats::Format;
use crate::options::{CastPolicy, Compression};
#[derive(Clone, Debug)]
pub struct WriteOptions {
pub lazy: bool,
pub chunk_elements: usize,
pub int_as: Option<IntKind>,
pub float_as: Option<FloatKind>,
pub dtype: Option<DType>,
pub shape: Option<Vec<usize>>,
pub cast_policy: CastPolicy,
pub format: Option<Format>,
pub compression: Compression,
pub pickle_protocol: u8,
pub fortran_order: bool,
}
impl Default for WriteOptions {
fn default() -> Self {
WriteOptions {
lazy: false,
chunk_elements: 1 << 20,
int_as: None,
float_as: None,
dtype: None,
shape: None,
cast_policy: CastPolicy::Strict,
format: None,
compression: Compression::None,
pickle_protocol: 4,
fortran_order: false,
}
}
}
impl WriteOptions {
pub fn new() -> Self {
Self::default()
}
pub fn lazy(mut self, yes: bool) -> Self {
self.lazy = yes;
self
}
pub fn chunk_elements(mut self, n: usize) -> Self {
self.chunk_elements = n.max(1);
self
}
pub fn int_as(mut self, kind: IntKind) -> Self {
self.int_as = Some(kind);
self
}
pub fn float_as(mut self, kind: FloatKind) -> Self {
self.float_as = Some(kind);
self
}
pub fn dtype(mut self, dt: DType) -> Self {
self.dtype = Some(dt);
self
}
pub fn shape(mut self, shape: impl Into<Vec<usize>>) -> Self {
self.shape = Some(shape.into());
self
}
pub fn cast_policy(mut self, p: CastPolicy) -> Self {
self.cast_policy = p;
self
}
pub fn format(mut self, fmt: Format) -> Self {
self.format = Some(fmt);
self
}
pub fn compression(mut self, c: Compression) -> Self {
self.compression = c;
self
}
pub fn pickle_protocol(mut self, p: u8) -> Self {
self.pickle_protocol = p.clamp(2, 5);
self
}
}
impl WriteOptions {
pub fn fortran_order(mut self, yes: bool) -> Self {
self.fortran_order = yes;
self
}
}