pub struct GroupedDataFrame {
source: DataFrame,
groups: Vec<(GroupKey, Vec<usize>)>,
}Expand description
A DataFrame partitioned by the values of one key column.
Produced by DataFrame::group_by. Holds the source frame plus one
(key, row-indices) pair per group; nothing is copied until you ask for
frames or extract.
§GC rooting
The source frame is preserved on R’s precious list
(R_PreserveObject) for this struct’s lifetime and released on drop —
order-independent, unlike the PROTECT stack, so the struct can be held
across arbitrary allocations (e.g. a locally built frame from
DataFrame::builder, which is unprotected once build() returns).
Without this, the per-group allocations in frames /
extract could collect the source mid-iteration.
Main-thread-only (holds a SEXP; !Send).
Fields§
§source: DataFrame§groups: Vec<(GroupKey, Vec<usize>)>Implementations§
Source§impl GroupedDataFrame
impl GroupedDataFrame
Sourcefn new(source: DataFrame, groups: Vec<(GroupKey, Vec<usize>)>) -> Self
fn new(source: DataFrame, groups: Vec<(GroupKey, Vec<usize>)>) -> Self
Root source on R’s precious list and pair it with precomputed groups.
R_PreserveObject conses onto the precious list — an allocation that can
itself GC — so PROTECT source across the call. Released on Drop.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&GroupKey, &[usize])>
pub fn iter(&self) -> impl Iterator<Item = (&GroupKey, &[usize])>
Iterate (key, row-indices) pairs in group order. Indices are 0-based
rows of source.
Sourcepub fn frames(&self) -> impl Iterator<Item = (&GroupKey, BuiltDataFrame)>
pub fn frames(&self) -> impl Iterator<Item = (&GroupKey, BuiltDataFrame)>
Iterate (key, sub-frame) pairs, materialising each group as its own
frame via DataFrame::select_rows.
Main thread only. Each yielded frame is an owned, GC-rooted
BuiltDataFrame (#1247) — safe to
hold across later iterations’ allocations. Deref (*sub) to pass the
view where a DataFrame is expected, e.g. to
NamedDataFrameListBuilder::push
(which protects on push, so the handle may drop right after).
Sourcepub fn extract<T>(&self) -> Result<Vec<(GroupKey, Vec<T>)>, DataFrameError>where
Vec<T>: FromDataFrame,
pub fn extract<T>(&self) -> Result<Vec<(GroupKey, Vec<T>)>, DataFrameError>where
Vec<T>: FromDataFrame,
Extract typed rows once, then partition them by group.
One Vec::<T>::from_dataframe pass over the whole frame, then a
move-partition by the stored indices — no per-group R subsetting and no
Clone bound. The result is plain Rust data (rayon-safe afterwards).
Trait Implementations§
Source§impl Drop for GroupedDataFrame
impl Drop for GroupedDataFrame
Auto Trait Implementations§
impl Freeze for GroupedDataFrame
impl RefUnwindSafe for GroupedDataFrame
impl Send for GroupedDataFrame
impl Sync for GroupedDataFrame
impl Unpin for GroupedDataFrame
impl UnsafeUnpin for GroupedDataFrame
impl UnwindSafe for GroupedDataFrame
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
Source§impl<T> SizeHint for Twhere
T: ?Sized,
impl<T> SizeHint for Twhere
T: ?Sized,
Source§default fn lower_bound(&self) -> usize
default fn lower_bound(&self) -> usize
core_io_internals)[u8; 12] could return any value between 0 and
12 inclusively as a correct implementation. Read moreSource§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read moreLayout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes