Skip to content

[Repo Assist] Fix IndexOutOfRangeException in Series.windowSize when series is shorter than window size#573

Merged
dsyme merged 6 commits intomasterfrom
repo-assist/fix-issue-559-window-ranges-bounds-2f1e556b1b40f4bb
Mar 9, 2026
Merged

[Repo Assist] Fix IndexOutOfRangeException in Series.windowSize when series is shorter than window size#573
dsyme merged 6 commits intomasterfrom
repo-assist/fix-issue-559-window-ranges-bounds-2f1e556b1b40f4bb

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented Mar 8, 2026

🤖 This is an automated PR from Repo Assist.

Fixes the IndexOutOfRangeException reported in #559.

Root Cause

Seq.windowRangesWithBounds in Common.fs generates the incomplete-window address ranges for Boundary.AtBeginning and Boundary.AtEnding. When the series length is less than (window size − 1), the loops produced out-of-bounds indices:

  • AtBeginning: for i in 1L .. size - 1L — when length = 0 this still emits (Incomplete, 0, 0), (Incomplete, 0, 1), … even though there are no elements.
  • AtEnding: for i in 1L .. size - 1L — when length < size - 1 the computed start address length - size + i becomes negative.

These invalid indices reached ArrayVectorBuilder.Build, which then threw.

Fix

AtBeginning — cap the loop upper bound at length:

for i in 1L .. min (size - 1L) length do ...

AtEnding — start the loop at max 1L (size - length) so the start address is never negative:

for i in max 1L (size - length) .. size - 1L do ...

Both changes are a one-liner and leave the normal (non-degenerate) case unchanged.

Regression Tests

Two new NUnit tests added in Series.fs:

  • Series.windowSize with AtBeginning does not throw when size exceeds series length — covers empty series (size 1 and 2) and a one-element series with a window of size 3.
  • Series.windowSize with AtEnding does not throw when size exceeds series length — same cases for the AtEnding boundary.

Test Status

The library builds successfully (dotnet build src/Deedle/Deedle.fsproj). The test project targets net5.0, which is not available in the current environment (only .NET 8+ installed), so the test suite could not be executed locally. The fix logic was verified manually with F# Interactive against the expected outputs. The tests will run in the project's CI on a net5.0 runner.

Generated by Repo Assist ·

To install this agentic workflow, run

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

…orter than window size

When Boundary.AtBeginning or Boundary.AtEnding is set and the series length
is less than (window size - 1), the incomplete-window index loops would
generate out-of-bounds addresses, causing an IndexOutOfRangeException when
the vector tries to materialise the window.

For AtBeginning: cap the upper bound of the loop at 'length' so no index
beyond the last element is ever emitted.

For AtEnding: start the loop at max(1, size - length) so that the computed
start address (length - size + i) is never negative.

Closes #559

Co-authored-by: Copilot <[email protected]>
@dsyme
Copy link
Copy Markdown
Member

dsyme commented Mar 8, 2026

/repo-assist fix broken CI, update R installation process and scripts as needed

@dsyme dsyme merged commit 7748846 into master Mar 9, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-559-window-ranges-bounds-2f1e556b1b40f4bb branch March 9, 2026 12:45
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