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: &Series,
group_idx: IdxSize,
) -> PolarsResult<()>;
unsafe fn update_groups(
&mut self,
values: &Series,
group_idxs: &[IdxSize],
) -> PolarsResult<()>;
unsafe fn combine(
&mut self,
other: &dyn GroupedReduction,
group_idxs: &[IdxSize],
) -> PolarsResult<()>;
unsafe fn gather_combine(
&mut self,
other: &dyn GroupedReduction,
subset: &[IdxSize],
group_idxs: &[IdxSize],
) -> PolarsResult<()>;
unsafe fn partition(
self: Box<Self>,
partition_sizes: &[IdxSize],
partition_idxs: &[IdxSize],
) -> Vec<Box<dyn GroupedReduction>>;
fn finalize(&mut self) -> PolarsResult<Series>;
fn as_any(&self) -> &dyn Any;
}
Expand description
A reduction with groups.
Each group has its own reduction state that values can be aggregated into.
Required Methods§
Sourcefn new_empty(&self) -> Box<dyn GroupedReduction>
fn new_empty(&self) -> Box<dyn GroupedReduction>
Returns a new empty reduction.
Sourcefn reserve(&mut self, additional: usize)
fn reserve(&mut self, additional: usize)
Reserves space in this GroupedReduction for an additional number of groups.
Sourcefn resize(&mut self, num_groups: IdxSize)
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.
Sourcefn update_group(
&mut self,
values: &Series,
group_idx: IdxSize,
) -> PolarsResult<()>
fn update_group( &mut self, values: &Series, group_idx: IdxSize, ) -> PolarsResult<()>
Updates the specified group with the given values.
Sourceunsafe fn update_groups(
&mut self,
values: &Series,
group_idxs: &[IdxSize],
) -> PolarsResult<()>
unsafe fn update_groups( &mut self, values: &Series, group_idxs: &[IdxSize], ) -> PolarsResult<()>
Updates this GroupedReduction with new values. values[i] should be added to reduction self[group_idxs[i]].
§Safety
group_idxs[i] < self.num_groups() for all i.
Sourceunsafe fn combine(
&mut self,
other: &dyn GroupedReduction,
group_idxs: &[IdxSize],
) -> PolarsResult<()>
unsafe fn combine( &mut self, other: &dyn GroupedReduction, group_idxs: &[IdxSize], ) -> PolarsResult<()>
Combines this GroupedReduction with another. Group other[i] should be combined into group self[group_idxs[i]].
§Safety
group_idxs[i] < self.num_groups() for all i.
Sourceunsafe fn gather_combine(
&mut self,
other: &dyn GroupedReduction,
subset: &[IdxSize],
group_idxs: &[IdxSize],
) -> PolarsResult<()>
unsafe fn gather_combine( &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.
Sourceunsafe fn partition(
self: Box<Self>,
partition_sizes: &[IdxSize],
partition_idxs: &[IdxSize],
) -> Vec<Box<dyn GroupedReduction>>
unsafe fn partition( self: Box<Self>, partition_sizes: &[IdxSize], partition_idxs: &[IdxSize], ) -> Vec<Box<dyn GroupedReduction>>
Partitions this GroupedReduction into several partitions.
The ith group of this GroupedReduction should becomes the group_idxs[i] group in partition partition_idxs[i].
§Safety
partitions_idxs[i] < partition_sizes.len() for all i. group_idxs[i] < partition_sizes[partition_idxs[i]] for all i. Each partition p has an associated set of group_idxs, this set contains 0..partition_size[p] exactly once.
Sourcefn finalize(&mut self) -> PolarsResult<Series>
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.