Skip to content

fix: reject h < 1 in ConformalIntervals at construction - #1224

Open
cjck944084735-dot wants to merge 1 commit into
Nixtla:mainfrom
cjck944084735-dot:fix/conformal-intervals-h-validation
Open

fix: reject h < 1 in ConformalIntervals at construction#1224
cjck944084735-dot wants to merge 1 commit into
Nixtla:mainfrom
cjck944084735-dot:fix/conformal-intervals-h-validation

Conversation

@cjck944084735-dot

Copy link
Copy Markdown

Summary

ConformalIntervals validated n_windows but not h, so ConformalIntervals(h=0) constructed successfully and only failed later — at interval-computation time — with a bare ZeroDivisionError from (n_samples - 1) // h in _conformity_scores, pointing nowhere near the bad argument.

Fixes #1221.

The fix

ConformalIntervals.__init__ now rejects h < 1 with a clear message, mirroring the existing n_windows < 2 check:

>>> ConformalIntervals(h=0)
ValueError: h must be at least one to compute conformal intervals

Testing

  • New test_conformal_intervals_invalid_h in tests/test_models.py: asserts h=0 and a negative h raise ValueError at construction.
  • Verified the full flow still works for a valid h (Naive + ConformalIntervals(h=4) produces lo-80/hi-80 as before), and that the bare ZeroDivisionError from the issue is gone.
  • Ran the conformal test subset of 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 unpatched main in this environment (numba-version related), not introduced by this change.
  • ruff check (repo config: F) passes on both changed files.

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
@CLAassistant

CLAassistant commented Aug 29, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@cjck944084735-dot

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core] ConformalIntervals accepts h=0 and later raises ZeroDivisionError in _conformity_scores

2 participants