GroupedReduction

Trait GroupedReduction 

Source
pub trait GroupedReduction:
    Any
    + Send
    + Sync {
    // Required methods
    fn new_empty(&self) -> Box<dyn GroupedReduction>;
    fn reserve(&mut self, additional: usize);
    fn resize(&mut self, num_groups: IdxSize);
    fn update_group(
        &mut self,
        values: &Column,
        group_idx: IdxSize,
        seq_id: u64,
    ) -> PolarsResult<()>;
    unsafe fn update_groups_while_evicting(
        &mut self,
        values: &Column,
        subset: &[IdxSize],
        group_idxs: &[EvictIdx],
        seq_id: u64,
    ) -> PolarsResult<()>;
    unsafe fn combine_subset(
        &mut self,
        other: &dyn GroupedReduction,
        subset: &[IdxSize],
        group_idxs: &[IdxSize],
    ) -> PolarsResult<()>;
    fn take_evictions(&mut self) -> Box<dyn GroupedReduction>;
    fn finalize(&mut self) -> PolarsResult<Series>;
    fn as_any(&self) -> &dyn Any;

    // Provided method
    unsafe fn update_groups_subset(
        &mut self,
        values: &Column,
        subset: &[IdxSize],
        group_idxs: &[IdxSize],
        seq_id: u64,
    ) -> PolarsResult<()> { ... }
}
Expand description

A reduction with groups.

Each group has its own reduction state that values can be aggregated into.

Required Methods§

Source

fn new_empty(&self) -> Box<dyn GroupedReduction>

Returns a new empty reduction.

Source

fn reserve(&mut self, additional: usize)

Reserves space in this GroupedReduction for an additional number of groups.

Source

fn resize(&mut self, num_groups: IdxSize)

Resizes this GroupedReduction to the given number of groups.

While not an actual member of the trait, the safety preconditions below refer to self.num_groups() as given by the last call of this function.

Source

fn update_group( &mut self, values: &Column, group_idx: IdxSize, seq_id: u64, ) -> PolarsResult<()>

Updates the specified group with the given values.

For order-sensitive grouped reductions, seq_id can be used to resolve order between calls/multiple reductions.

Source

unsafe fn update_groups_while_evicting( &mut self, values: &Column, subset: &[IdxSize], group_idxs: &[EvictIdx], seq_id: u64, ) -> PolarsResult<()>

Updates this GroupedReduction with new values. values[subset[i]] should be added to reduction self[group_idxs[i]]. For order-sensitive grouped reductions, seq_id can be used to resolve order between calls/multiple reductions. If the group_idxs[i] has its evict bit set the current value in the group should be evicted and reset before updating.

§Safety

The subset and group_idxs are in-bounds.

Source

unsafe fn combine_subset( &mut self, other: &dyn GroupedReduction, subset: &[IdxSize], group_idxs: &[IdxSize], ) -> PolarsResult<()>

Combines this GroupedReduction with another. Group other[subset[i]] should be combined into group self[group_idxs[i]].

§Safety

subset[i] < other.num_groups() for all i. group_idxs[i] < self.num_groups() for all i.

Source

fn take_evictions(&mut self) -> Box<dyn GroupedReduction>

Take the accumulated evicted groups.

Source

fn finalize(&mut self) -> PolarsResult<Series>

Returns the finalized value per group as a Series.

After this operation the number of groups is reset to 0.

Source

fn as_any(&self) -> &dyn Any

Returns this GroupedReduction as a dyn Any.

Provided Methods§

Source

unsafe fn update_groups_subset( &mut self, values: &Column, subset: &[IdxSize], group_idxs: &[IdxSize], seq_id: u64, ) -> PolarsResult<()>

Updates this GroupedReduction with new values. values[subset[i]] should be added to reduction self[group_idxs[i]]. For order-sensitive grouped reductions, seq_id can be used to resolve order between calls/multiple reductions.

§Safety

The subset and group_idxs are in-bounds.

Implementors§