Skip to content

[Repo Assist] Add Frame.nestRowsBy — closes #60#652

Merged
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-60-nestRowsBy-39caf6db12b4efee
Mar 19, 2026
Merged

[Repo Assist] Add Frame.nestRowsBy — closes #60#652
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-60-nestRowsBy-39caf6db12b4efee

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 Repo Assist — implementing the nestRowsBy feature requested in #60.

Problem

Frame.nestBy takes a single key-selector and groups rows, but the resulting inner frames keep the original row keys. When the frame is keyed by tuples (or any compound key), callers almost always want to extract a sub-key as the inner row key. Currently this requires an extra .Series.map (fun _ df -> df |> Frame.indexRowsWith …) step.

Solution

Add Frame.nestRowsBy (groupSel: 'K -> 'K1) (rowSel: 'K -> 'K2):

// Group by first element of a tuple key, use second element as inner row key
frame |> Frame.nestRowsBy fst snd
// → Series<'K1, Frame<'K2, 'C>>

// More explicit example
let df =
    Frame.ofColumns [ "V" => Series.ofValues [10; 20; 30; 40] ]
    |> Frame.indexRowsWith [("North","Jan"); ("North","Feb"); ("South","Jan"); ("South","Feb")]

let nested = df |> Frame.nestRowsBy fst snd
// nested.["North"].RowKeys = ["Jan"; "Feb"]   ← clean inner key
// nested.["South"].RowKeys = ["Jan"; "Feb"]
```

## Implementation

- **`FrameModule.fs`**: `nestRowsBy` defined after `nestBy`; calls `nestBy groupSel` then applies `indexRowsWith (Seq.map rowSel)` to each inner frame.
- **`FrameExtensions.fs`**: matching `NestRowsBy(frame, groupSelector:Func<_,_>, rowSelector:Func<_,_>)` C# extension.
- **`tests/Deedle.Tests/Frame.fs`**: one test covering the tuple-key case.

The change is **purely additive** — `nestBy` is unchanged.

## Test Status

```
Passed! - Failed: 0, Passed: 670, Skipped: 0, Total: 670

All 670 tests pass on Ubuntu.

Generated by Repo Assist ·

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@30f2254f2a7a944da1224df45d181a3f8faefd0d

nestRowsBy (groupSel: 'K -> 'K1) (rowSel: 'K -> 'K2) groups rows by
groupSel and re-indexes each sub-frame's rows using rowSel, returning
Series<'K1, Frame<'K2, 'C>>.

The common use case is a tuple-keyed frame where you want to group by
the first element and keep only the second element as the inner row key:

    frame |> Frame.nestRowsBy fst snd

- FrameModule.fs: nestRowsBy implemented after nestBy (calls nestBy then
  re-indexes inner frames with indexRowsWith)
- FrameExtensions.fs: matching NestRowsBy C# extension (groupSelector +
  rowSelector Func arguments)
- Frame.fs: one test covering the core tuple-key use case

All 670 tests pass.

Co-authored-by: Copilot <[email protected]>
@dsyme dsyme marked this pull request as ready for review March 19, 2026 01:11
@dsyme dsyme merged commit ba9738c into master Mar 19, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-60-nestRowsBy-39caf6db12b4efee branch March 19, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant