Skip to content

[Repo Assist] Add Series.windowWhileFromEnd and Series.chunkWhileFromEnd#648

Merged
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-256-window-while-from-end-8fe4717c20618d20
Mar 18, 2026
Merged

[Repo Assist] Add Series.windowWhileFromEnd and Series.chunkWhileFromEnd#648
dsyme merged 2 commits intomasterfrom
repo-assist/fix-issue-256-window-while-from-end-8fe4717c20618d20

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated PR from Repo Assist.

Closes #256

Summary

This PR implements the feature requested in #256: a variant of Series.windowWhile / Series.chunkWhile where the key of each window/chunk is its last element (i.e., windows anchored at the end rather than the start).

New API

Series.windowWhileFromEnd / Series.windowWhileIntoFromEnd

For each key k, produces the window ending at k that extends back as far as cond(startKey, k) returns true. The key of each output window is the last (end) element.

// Series: [ 01=>01; 10=>10; 11=>11; 14=>14; 21=>21 ]
// cond: fun k1 k2 -> k1/10 = k2/10  (same decade)

// windowWhile (key = first element):
// 1 => [1];  10 => [10;11;14];  11 => [11;14];  14 => [14];  21 => [21]

// windowWhileFromEnd (key = last element):
// 1 => [1];  10 => [10];  11 => [10;11];  14 => [10;11;14];  21 => [21]

Series.chunkWhileFromEnd / Series.chunkWhileIntoFromEnd

Same non-overlapping chunking as chunkWhile, but each chunk is keyed by its last element instead of its first.

// chunkWhile:     1 => [1];  10 => [10;11;14];  21 => [21]
// chunkWhileFromEnd: 1 => [1];  14 => [10;11;14];  21 => [21]
```

## Implementation

| File | Change |
|---|---|
| `Common.fs` | New `Seq.windowRangesWhileFromEnd` – backward-extending window ranges |
| `Index.fs` | New `WindowWhileFromEnd` discriminated union case + `Aggregation.WindowWhileFromEnd` static factory |
| `LinearIndex.fs` | Handle `WindowWhileFromEnd` in aggregation dispatch |
| `SeriesModule.fs` | Four new public functions |
| `tests/Deedle.Tests/Series.fs` | Two new tests |

## Naming convention check

The maintainer asked to verify `FromEnd` is appropriate. Checked the existing API:
- No `FromEnd` functions exist yet.
- Direction-parameterised variants (e.g. `fillMissing Direction.Backward`) use `Direction` parameters, not suffixes.
- Standalone directional variants (`takeLast`, `skipLast`) use `Last`.
- `FromEnd` is the most descriptive suffix here (the window is anchored at/from its end), and it's the naming that was suggested in the prior discussion. ✅

## Test Status

```
dotnet test tests/Deedle.Tests/Deedle.Tests.fsproj -c Release
Passed! - Failed: 0, Passed: 4, Skipped: 0 (4 windowing tests including 2 new)
Build: 0 errors, 4 warnings (pre-existing)

Generated by Repo Assist for issue #256 ·

To install this agentic workflow, run

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

Implements issue #256: 'Aggregating with key at the end'.

- Series.windowWhileIntoFromEnd / windowWhileFromEnd: sliding windows
  where each window ENDS at the current key, extending backward while
  cond(startKey, endKey) holds. Backed by a new WindowWhileFromEnd
  aggregation type and Seq.windowRangesWhileFromEnd.
- Series.chunkWhileIntoFromEnd / chunkWhileFromEnd: same chunking as
  chunkWhile but the key of each chunk is the LAST key of the chunk.
- Aggregation.WindowWhileFromEnd static factory method for C# users.
- Two new tests covering the expected behavior.

The naming convention FromEnd is used (checked against existing API:
no established convention exists; Direction.Backward/Forward is used
for parameterised variants but FromEnd is clearest for standalone fns).

Co-authored-by: Copilot <[email protected]>
@dsyme dsyme marked this pull request as ready for review March 18, 2026 16:22
@dsyme dsyme merged commit 029d39c into master Mar 18, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-256-window-while-from-end-8fe4717c20618d20 branch March 18, 2026 16:27
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.

Aggregating with key at the end

1 participant