fix: reject h < 1 in ConformalIntervals at construction - #1224
Open
cjck944084735-dot wants to merge 1 commit into
Open
fix: reject h < 1 in ConformalIntervals at construction#1224cjck944084735-dot wants to merge 1 commit into
cjck944084735-dot wants to merge 1 commit into
Conversation
ConformalIntervals validated n_windows but not h, so ConformalIntervals(h=0) constructed successfully and only failed later with a bare ZeroDivisionError from the (n_samples - 1) // h in _conformity_scores, pointing nowhere near the bad argument. Raise a clear ValueError at construction instead, mirroring the existing n_windows check. Fixes Nixtla#1221
|
|
Author
|
Transparency note: this fix was drafted with the help of an AI coding agent under the direction of the account owner, who reproduced the issue, reviewed the diff line by line, ran the verification (repro before/after, the new regression test, and the conformal test subset), and takes responsibility for the change. Happy to answer any questions about the details. |
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.
Summary
ConformalIntervalsvalidatedn_windowsbut noth, soConformalIntervals(h=0)constructed successfully and only failed later — at interval-computation time — with a bareZeroDivisionErrorfrom(n_samples - 1) // hin_conformity_scores, pointing nowhere near the bad argument.Fixes #1221.
The fix
ConformalIntervals.__init__now rejectsh < 1with a clear message, mirroring the existingn_windows < 2check:Testing
test_conformal_intervals_invalid_hintests/test_models.py: assertsh=0and a negativehraiseValueErrorat construction.h(Naive+ConformalIntervals(h=4)produceslo-80/hi-80as before), and that the bareZeroDivisionErrorfrom the issue is gone.tests/test_models.py: the only failures are 3 pre-existing ones (test_arima_conformal_prediction,test_mfles_conformal_prediction,test_sklearn_model_with_conformal_intervals) that fail identically on unpatchedmainin this environment (numba-version related), not introduced by this change.ruff check(repo config:F) passes on both changed files.