[Fix] Fix off-by-one in Covobs pos bounds check - #288
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes an off-by-one error in Covobs position validation so out-of-range pos indices produce a clear ValueError (instead of later, less-informative indexing errors), and adds a regression test to lock in the behavior.
Changes:
- Tighten
Covobs.__init__bounds check frompos > Ntopos >= N. - Add a unit test ensuring
pos == NraisesValueError. - Add a direct import of
Covobsin the test module to exercise the constructor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pyerrors/covobs.py | Fixes upper-bound validation for pos to prevent out-of-range indexing. |
| tests/covobs_test.py | Adds a regression test for pos being too large. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
34
to
35
| if pos >= self.N: | ||
| raise ValueError(f'pos {pos} too large for covariance matrix with dimension {self.N}x{self.N}!') |
s-kuberski
approved these changes
Jul 15, 2026
s-kuberski
left a comment
Collaborator
There was a problem hiding this comment.
Very good, thanks for spotting it!
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.
Follow up to the making exception messages more explicit: This highlighted a small bug that let to a misleading exception message.