Skip to content

[Repo Assist] Fix: throw InvalidOperationException for inexact Lookup on unordered series — closes #220#644

Merged
dsyme merged 4 commits intomasterfrom
repo-assist/fix-issue-220-unordered-lookup-6fb167b5bdf05138
Mar 18, 2026
Merged

[Repo Assist] Fix: throw InvalidOperationException for inexact Lookup on unordered series — closes #220#644
dsyme merged 4 commits intomasterfrom
repo-assist/fix-issue-220-unordered-lookup-6fb167b5bdf05138

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 Repo Assist — automated bug fix.

Summary

Fixes #220. Before this change, calling Series.Get/TryGet with Lookup.Smaller, Lookup.Greater, Lookup.ExactOrSmaller (missing key), or Lookup.ExactOrGreater (missing key) on an unordered series silently returned OptionalValue.Missing/None. This masked programming errors where callers passed an unordered series by mistake.

Root Cause

In src/Deedle/Indices/LinearIndex.fs, the Lookup dispatch had guarded arms for inexact semantics (when x.isOrdered). When those guards failed for an unordered index, the catch-all | _ -> OptionalValue.Missing silently ate the request instead of surfacing an error.

Fix

Added an explicit arm before the catch-all:

| _, (Lookup.Smaller | Lookup.ExactOrSmaller | Lookup.Greater | Lookup.ExactOrGreater) ->
    invalidOp "Lookup.Smaller/Greater is only supported on ordered series. Sort the series first (e.g. Series.sortByKey) before using inexact lookup."

This is consistent with how other ordered-only operations (KeyRange, windowing, resampling) are already protected with invalidOp.

Note: ExactOrSmaller/ExactOrGreater with an existing key still return the exact value even in an unordered series — that path is handled earlier in the match and is correct.

Tests

Added 4 new assertions to tests/Deedle.Tests/Series.fs:

  • Lookup.Smaller on existing key in unordered series → InvalidOperationException
  • Lookup.Greater on existing key in unordered series → InvalidOperationException
  • Lookup.ExactOrSmaller on absent key in unordered series → InvalidOperationException
  • Lookup.ExactOrGreater on absent key in unordered series → InvalidOperationException

Test Status

✅ All 613 tests pass on Linux (net9.0).

Generated by Repo Assist ·

To install this agentic workflow, run

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

…ordered series (closes #220)

Before this change, calling Series.Get/TryGet with Lookup.Smaller, Lookup.Greater,
or the ExactOr variants on an unordered series (and with a missing key for ExactOr
variants) silently returned OptionalValue.Missing / None. This masked bugs where
callers passed an unordered series by mistake.

The fix adds an explicit match arm in LinearIndex.Lookup that raises InvalidOperationException
with a clear message, consistent with how other ordered-only operations (windowing, resampling,
KeyRange) are already guarded.

Co-authored-by: Copilot <[email protected]>
The test 'series with datetime keys preserves time in Format' was failing
on Windows because DateTime.ToString() uses the locale's AM/PM format.
Apply the same fix as PR #643: use 'yyyy-MM-dd HH:mm:ss' with
InvariantCulture for DateTime keys that have a non-zero time component.

Co-authored-by: Copilot <[email protected]>
@github-actions
Copy link
Copy Markdown
Contributor Author

Commit pushed: 93b1609

Generated by Repo Assist

@dsyme dsyme marked this pull request as ready for review March 18, 2026 15:14
@dsyme dsyme merged commit d9e2e6a into master Mar 18, 2026
2 checks passed
@dsyme dsyme deleted the repo-assist/fix-issue-220-unordered-lookup-6fb167b5bdf05138 branch March 18, 2026 15:31
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.

Throw exception when doing e.g. Lookup.Smaller on unsorted frame

1 participant