Expand description
Run-length encoded sequences over Apache Arrow arrays.
This crate builds on runlength and uses its plans and merge rules, but
stores values as an Arrow array, so values can be of any Arrow type:
numbers, strings, dictionaries, lists, structs, and nulls in any of them.
- Combining sequences gathers values through a
runlength::Planand applies any Arrow kernel (kernelshas the usual ones). - Merging uses the same rule as the core crate for every type
(
identical_neighbours). ArrowRleBatchkeys sequences by a table of key columns of any types, and converts to one long table for polars or pandas.
use std::sync::Arc;
use arrow_array::{ArrayRef, StringArray};
use runlength_arrow::{ArrowRle, kernels};
let names: ArrayRef = Arc::new(StringArray::from(vec!["a", "a", "b", "c", "c"]));
let rle = ArrowRle::from_dense(names).unwrap();
assert_eq!(rle.runs(), vec![2, 1, 2]);
let other: ArrayRef = Arc::new(StringArray::from(vec!["a", "x", "c", "c", "c"]));
let other = ArrowRle::from_dense(other).unwrap();
let same = rle.zip_with(&other, None, None, kernels::eq).unwrap();
assert_eq!(same.runs(), vec![1, 2, 2]);Modules§
- kernels
- Element-wise kernels in the shape
zip_withexpects.
Structs§
- Arrow
Rle - A run-length encoded sequence whose values are an Arrow array of any type.
- Arrow
RleBatch - Many Arrow-backed sequences, each identified by a row of a key table.
- Overlap
Plan - Which intervals cover each segment, for aggregating interval values in any way.
- Plan
Many - How to combine
ksequences, computed from their run ends alone: thek-input version ofPlan.
Enums§
- Agg
- How
coverage_aggcombines the intervals covering a position. - Error
- Errors from Arrow-backed sequences.
- How
- Which keys a combination of two batches keeps, as in a DataFrame join.
- Keep
- Which value a merged group keeps when its runs hold different values.
- Slice
Agg - How
ArrowRle::slice_aggreduces each slice. Null values are skipped, as in polars and pandas.
Functions§
- common_
numeric_ type - The type two numeric types are converted to before combining them:
themselves if equal,
Float64if either is a float,Int64otherwise.Noneif either is not numeric. - concat
- Joins sequences end to end and merges identical neighbours, including at the joins. All sequences must have the same value type.
- coverage
- Coverage of half-open intervals
[start, end). - coverage_
agg - Coverage of half-open intervals
[start, end)with any aggregation. - coverage_
agg_ by_ key coverage_aggper key, computed in parallel; seecoverage_by_keyfor the keys.- coverage_
by_ key coverageper key, computed in parallel.- default_
fill - The fill value operators use for a value type: zero for numbers,
falsefor booleans, andNonefor other types (which then require equal lengths). - identical_
neighbours - For each pair of neighbouring values, whether they are identical by the
same rule as the core crate’s
Identical: nulls are identical to nulls,NaNtoNaN, and-0.0is not identical to0.0. - overlap_
plan - Computes the
OverlapPlanfor intervals[start, end). - overlap_
plan_ by_ key runlength::overlap_planper key, as one long table: the key columns, thenstartandendof each segment andids, a list of the intervals covering it (positions in the input, sorted). Keys appear in order of first appearance; each key’s segments cover0..max(end)of its own intervals.- plan_
many - Computes the
PlanManyfor sequences with the given run ends. - zip_
many - Combines several sequences position by position, and merges the result.