pub struct ArrowRle { /* private fields */ }Expand description
A run-length encoded sequence whose values are an Arrow array of any type.
Like runlength::Rle, it stores cumulative run ends and one value per
run, starts at position 0, and has no zero-length runs. Values may contain
nulls; a null is a value like any other and merges with neighbouring nulls.
Implementations§
Source§impl ArrowRle
impl ArrowRle
Sourcepub fn sum(&self) -> Result<ArrayRef>
pub fn sum(&self) -> Result<ArrayRef>
The sum over all positions, as one value of the values’ type. Integer sums wrap on overflow.
Sourcepub fn mean(&self) -> Result<Option<f64>>
pub fn mean(&self) -> Result<Option<f64>>
The mean over all positions, or None if the sequence is empty.
Sourcepub fn variance(&self, ddof: i64) -> Result<Option<f64>>
pub fn variance(&self, ddof: i64) -> Result<Option<f64>>
The variance over all positions with ddof delta degrees of freedom,
or None if len() <= ddof.
Source§impl ArrowRle
impl ArrowRle
Sourcepub fn try_new(ends: Vec<i64>, values: ArrayRef) -> Result<Self>
pub fn try_new(ends: Vec<i64>, values: ArrayRef) -> Result<Self>
Builds a sequence from cumulative run ends and one value per run.
Sourcepub fn from_runs(runs: &[i64], values: ArrayRef) -> Result<Self>
pub fn from_runs(runs: &[i64], values: ArrayRef) -> Result<Self>
Builds a sequence from run lengths and one value per run. Zero-length runs are dropped; neighbouring identical values are kept as they are.
Sourcepub fn from_dense(values: ArrayRef) -> Result<Self>
pub fn from_dense(values: ArrayRef) -> Result<Self>
Encodes a dense array, merging identical neighbours.
Sourcepub fn from_rle<T: ArrowPrimitiveType>(rle: &Rle<T::Native>) -> Self
pub fn from_rle<T: ArrowPrimitiveType>(rle: &Rle<T::Native>) -> Self
Converts a core sequence of primitive values.
Sourcepub fn to_rle<T: ArrowPrimitiveType>(&self) -> Result<Rle<T::Native>>
pub fn to_rle<T: ArrowPrimitiveType>(&self) -> Result<Rle<T::Native>>
Converts to a core sequence of primitive values. The values must be of
type T and contain no nulls.
pub fn data_type(&self) -> &DataType
pub fn is_empty(&self) -> bool
pub fn num_runs(&self) -> usize
pub fn into_parts(self) -> (Vec<i64>, ArrayRef)
Sourcepub fn run_index(&self, pos: i64) -> Option<usize>
pub fn run_index(&self, pos: i64) -> Option<usize>
The index of the run containing pos, if pos is in range.
Sourcepub fn slice(&self, start: i64, end: i64) -> ArrowRle
pub fn slice(&self, start: i64, end: i64) -> ArrowRle
The positions start..end as a new sequence starting at 0, clamped to
the sequence. The values are a zero-copy slice.
Sourcepub fn getitems(&self, starts: &[i64], ends: &[i64]) -> Result<ArrowRleBatch>
pub fn getitems(&self, starts: &[i64], ends: &[i64]) -> Result<ArrowRleBatch>
Many slices at once, as a batch with one key column, slice, holding
the slice number. Each interval needs 0 <= start <= end.
Sourcepub fn plan_with(&self, other: &ArrowRle) -> Plan
pub fn plan_with(&self, other: &ArrowRle) -> Plan
The plan for combining this sequence with other. See Plan.
Sourcepub fn identical_neighbours(&self) -> Result<Vec<bool>>
pub fn identical_neighbours(&self) -> Result<Vec<bool>>
For each pair of neighbouring runs, whether their values are identical.
Sourcepub fn is_merged(&self) -> Result<bool>
pub fn is_merged(&self) -> Result<bool>
Whether no two neighbouring runs hold identical values.
Sourcepub fn merge_mask(self, mask: &[bool], keep: Keep) -> Result<Self>
pub fn merge_mask(self, mask: &[bool], keep: Keep) -> Result<Self>
Merges run i + 1 into run i wherever mask[i] is true, keeping the
first or last value of each merged group.
Sourcepub fn zip_with<F>(
&self,
other: &ArrowRle,
fill_a: Option<&dyn Array>,
fill_b: Option<&dyn Array>,
f: F,
) -> Result<ArrowRle>
pub fn zip_with<F>( &self, other: &ArrowRle, fill_a: Option<&dyn Array>, fill_b: Option<&dyn Array>, f: F, ) -> Result<ArrowRle>
Combines two sequences position by position and merges the result.
f receives the values of both sides gathered onto the plan’s
segments (two arrays of equal length) and must return one value per
segment; any Arrow kernel fits. The shorter side is padded with its
fill value, a single value of the same type; with no fill value,
unequal lengths are an error.
Sourcepub fn zip_with_raw<F>(
&self,
other: &ArrowRle,
fill_a: Option<&dyn Array>,
fill_b: Option<&dyn Array>,
f: F,
) -> Result<ArrowRle>
pub fn zip_with_raw<F>( &self, other: &ArrowRle, fill_a: Option<&dyn Array>, fill_b: Option<&dyn Array>, f: F, ) -> Result<ArrowRle>
Like zip_with but without merging the result.
Sourcepub fn map<F>(&self, f: F) -> Result<ArrowRle>
pub fn map<F>(&self, f: F) -> Result<ArrowRle>
Applies an Arrow kernel to the run values and merges the result.
Sourcepub fn cast(&self, data_type: &DataType) -> Result<ArrowRle>
pub fn cast(&self, data_type: &DataType) -> Result<ArrowRle>
Casts the values to data_type and merges any neighbours that become
identical (for example when floats are truncated to integers).
Sourcepub fn zip_with_default(&self, other: &ArrowRle, f: Kernel) -> Result<ArrowRle>
pub fn zip_with_default(&self, other: &ArrowRle, f: Kernel) -> Result<ArrowRle>
Combines with other using default_fill on each side, and merges.
Source§impl ArrowRle
impl ArrowRle
Sourcepub fn add(&self, other: &ArrowRle) -> Result<ArrowRle>
pub fn add(&self, other: &ArrowRle) -> Result<ArrowRle>
Element-wise addition (integer overflow is an error). The shorter side is padded with default_fill.
Sourcepub fn sub(&self, other: &ArrowRle) -> Result<ArrowRle>
pub fn sub(&self, other: &ArrowRle) -> Result<ArrowRle>
Element-wise subtraction (integer overflow is an error). The shorter side is padded with default_fill.
Sourcepub fn mul(&self, other: &ArrowRle) -> Result<ArrowRle>
pub fn mul(&self, other: &ArrowRle) -> Result<ArrowRle>
Element-wise multiplication (integer overflow is an error). The shorter side is padded with default_fill.
Sourcepub fn div(&self, other: &ArrowRle) -> Result<ArrowRle>
pub fn div(&self, other: &ArrowRle) -> Result<ArrowRle>
Element-wise division (integer division by zero is an error). The shorter side is padded with default_fill.
Sourcepub fn elem_eq(&self, other: &ArrowRle) -> Result<ArrowRle>
pub fn elem_eq(&self, other: &ArrowRle) -> Result<ArrowRle>
Element-wise ==. The shorter side is padded with default_fill.
Sourcepub fn elem_ne(&self, other: &ArrowRle) -> Result<ArrowRle>
pub fn elem_ne(&self, other: &ArrowRle) -> Result<ArrowRle>
Element-wise !=. The shorter side is padded with default_fill.
Sourcepub fn elem_lt(&self, other: &ArrowRle) -> Result<ArrowRle>
pub fn elem_lt(&self, other: &ArrowRle) -> Result<ArrowRle>
Element-wise <. The shorter side is padded with default_fill.
Sourcepub fn elem_le(&self, other: &ArrowRle) -> Result<ArrowRle>
pub fn elem_le(&self, other: &ArrowRle) -> Result<ArrowRle>
Element-wise <=. The shorter side is padded with default_fill.
Sourcepub fn elem_gt(&self, other: &ArrowRle) -> Result<ArrowRle>
pub fn elem_gt(&self, other: &ArrowRle) -> Result<ArrowRle>
Element-wise >. The shorter side is padded with default_fill.
Sourcepub fn elem_ge(&self, other: &ArrowRle) -> Result<ArrowRle>
pub fn elem_ge(&self, other: &ArrowRle) -> Result<ArrowRle>
Element-wise >=. The shorter side is padded with default_fill.
Source§impl ArrowRle
impl ArrowRle
Sourcepub fn slice_agg(
&self,
starts: &[i64],
ends: &[i64],
agg: SliceAgg,
) -> Result<ArrayRef>
pub fn slice_agg( &self, starts: &[i64], ends: &[i64], agg: SliceAgg, ) -> Result<ArrayRef>
Reduces many slices without copying them, in parallel: entry k of
the result reduces positions starts[k]..ends[k] (clamped to the
sequence) with agg. Values must be numeric or boolean.
use std::sync::Arc;
use arrow_array::{Array, Float64Array, Int64Array};
use runlength_arrow::{ArrowRle, SliceAgg};
let rle = ArrowRle::from_runs(&[3, 2], Arc::new(Int64Array::from(vec![1, 4]))).unwrap();
let means = rle.slice_agg(&[0, 2], &[2, 5], SliceAgg::Mean).unwrap();
let means = means.as_any().downcast_ref::<Float64Array>().unwrap();
assert_eq!(means.values().to_vec(), vec![1.0, 3.0]);Source§impl ArrowRle
impl ArrowRle
Sourcepub fn shift(&self, distance: i64, fill: &dyn Array) -> Result<ArrowRle>
pub fn shift(&self, distance: i64, fill: &dyn Array) -> Result<ArrowRle>
Shifts values distance positions right (left if negative), keeping
the length; positions shifted in hold fill, a single value of the
same type. The result is merged.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for ArrowRle
impl !UnwindSafe for ArrowRle
impl Freeze for ArrowRle
impl Send for ArrowRle
impl Sync for ArrowRle
impl Unpin for ArrowRle
impl UnsafeUnpin for ArrowRle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more