Conversation
Adds Series.sweepLevel, which applies a summary function to each group
(as defined by a level projection) and then combines each element with
its group summary using a binary sweep operator. This is analogous to
R's sweep() and enables common operations like within-group normalisation
and mean-centring in a single expression.
Example:
s |> Series.sweepLevel fst Stats.sum (/) // fraction of group sum
s |> Series.sweepLevel fst Stats.mean (-) // demean within group
Implementation uses applyLevel to build the summary and Series.map to
look up each element's group summary by its level key, avoiding issues
with duplicate key lookups. Three tests are added for the normalise,
demean, and single-element-group cases.
Co-authored-by: Copilot <[email protected]>
9 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 Repo Assist — automated implementation
Summary
Implements
Series.sweepLevelas requested in #236. This function computes a group-level summary (viaapplyLevel) and then combines each element with its group's summary value using a binary operator — analogous to R'ssweep().New API
Series.sweepLevel (level : 'K1 -> 'K2) (summaryOp : Series<'K1,'V> -> 'R) (sweepOp : 'V -> 'R -> 'S) (series : Series<'K1,'V>) -> Series<'K1,'S>Usage examples
Implementation notes
applyLevelfor the group summary, thenSeries.mapto look up each element's group summary by its projected key. This avoids the duplicate-key pitfall that arises when usinggetAllwith repeated mapped keys.applyLevel/reduceLevelfunctions are unchanged — fully backwards-compatible.SeriesModule.fs(implementation) andTests/Series.fs(3 new tests).Test Status