Repository navigation
fix(ts): prevent overlapping AR and MA lags in SARIMAX configurations - #1661
Laasya priya Bhadri (laasyapriya2007) wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The fallback reduces both AR and MA orders when only one seasonal component overlaps, incorrectly discarding valid terms from the non-overlapping component.
1 open issue
What changed in this PR
This PR addresses #845 by preventing overlapping seasonal and non-seasonal lags from interrupting FLAML’s SARIMAX forecasting.
Changes:
- Clamp overlapping AR and MA orders during configuration conversion.
- Add a targeted retry for overlapping-lag errors, with warning logging and parameter updates.
- Add regression tests for combined overlap, single-component overlap, and unchanged valid configurations.
| File | Description |
|---|---|
test/automl/test_forecast.py |
Tests lag clamping and successful fitting and forecasting. |
flaml/automl/time_series/ts_model.py |
Adds configuration clamping and defensive fit recovery. |
Review effort: Balanced
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
Changes requested at 6d43bf0a128bbf6f755d3b538014832ce23f6c24: two independently reproduced P2 correctness issues.
-
Preserve valid sparse lag specifications.
SARIMAX(task="ts_forecast", p=[1,3], d=0, q=0, P=1, D=0, Q=0, s=12)now raisesTypeError: '>=' not supported between instances of 'list' and 'int'inconfig2params, although lags 1 and 3 do not overlap seasonal lag 12. The corresponding MA configuration (p=0, q=[1,3], P=0, Q=1, s=12) fails likewise. Both configurations actually fit and produce six finite predictions on exact main46bce0ce989aae0271e68e5daac5b8a9b0522b87in both native Windows Python 3.10 and 3.13 stacks. The new head fails during construction, before fitting. Handle scalar order counts and iterable lag specifications separately and add non-overlapping sparse-order regression coverage. -
Preserve the other valid order in the fallback. I independently confirmed Copilot's existing finding, without duplicating or resolving that thread. With post-init injected
(p,d,q)=(4,0,6)and seasonal(1,0,0,4), only AR overlaps, but the actual fitted backend order becomes(3,0,3)instead of retaining valid MA order 6. The MA-only analogue(6,0,4)/ seasonal(0,0,1,4)also fits(3,0,3)instead of(6,0,3). These are actual statsmodels construction/retry/fit results on both stacks, not simulated backend failures. The injection explicitly exercises the advertised defensive path; this is not a claim that normal built-in search necessarily reaches that path.
Validation: the intended scalar-overlap, targeted retry/logging, unrelated-error propagation, direct native fit/predict, repository regression and public AutoML control suite passes 16 cases per stack (32 total). The same test definitions on exact main give 7 expected feature-counterfactual failures and 9 passing controls per stack. The public AutoML starting-point case also passes on main, so it is a passing control, not proof that the invalid supplied trial was necessarily evaluated. The dedicated sparse-order probes add four current failures/four native main fit-predict controls; the fallback probes add four wrong-order reproductions/four prior unhandled-overlap controls. Original outputs and qualifications are retained; no contributor source was changed.
The planned Medium independent review-code execution remains blocked at its authenticated CLI prerequisite: no complementary reviewer, six-lens result or clean skill signoff is claimed. Driver-confirmed issues and current-head Balanced Copilot feedback are distinct evidence. No PR approval is submitted.
Posted by thinkall-agent-auto-reviewer
| # non-seasonal orders below the first seasonal lag to keep configs valid. | ||
| s = params.get("s", 0) | ||
| if s > 0: | ||
| if params.get("P", 0) > 0 and params.get("p", 0) >= s: |
There was a problem hiding this comment.
[P2] Keep valid sparse AR/MA lag lists working
These scalar comparisons reject existing valid statsmodels lag-list configs. For example, p=[1,3], q=0, P=1, D=0, Q=0, s=12, d=0 has no overlap, but construction now raises TypeError at p >= s; the MA analogue fails at q >= s. Both fit and produce six finite predictions on exact main in native Python 3.10/3.13 controls. Preserve iterable lag specifications rather than comparing them directly to the scalar seasonal period, with regression tests.
Posted by thinkall-agent-auto-reviewer
|
Thanks @thinkkll and Copilot for the reviews — both findings addressed in 3b13e2d. 1. Preserve the non-overlapping order in the fallback (both reviews) — agreed, this was a real flaw: the fallback clamped 2. Keep flexible (sparse) lag specifications valid — the scalar comparisons could raise Tests (extended Re: the earlier Build attempt failures (ubuntu 3.12/3.13) — the latest attempt of that run is green on all jobs; this push re-triggers CI. |
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
Verified the corrective delta from 6d43bf0a128bbf6f755d3b538014832ce23f6c24 to 3b13e2d493c6a24d34c206826b74a33cfd3f16cf. Both specifically reported P2 issues are corrected in the tested paths: valid sparse AR/MA lag lists/tuples pass through without scalar comparison errors, and the defensive AR-only/MA-only fallback preserves the other valid order (6) instead of clamping both components to 3.
On native Windows Python 3.10 and 3.13, 17 cases pass per stack (34 total). The same current test definitions against the previous head give 9 expected failures and 8 passing controls per stack. Coverage includes actual sparse-list statsmodels fit/six-step prediction, actual post-init defensive fallback fitted-order checks, NumPy-integer/scalar normalization, retained endog/exog data, retry logging and unrelated ValueError propagation. The fallback injection is explicitly a defensive-path test, not a claim that normal built-in search must reach it. Original failures and the earlier changes request remain preserved.
This clears only those two driver-confirmed findings, not whole-feature or independent review-code signoff. The planned Medium complementary six-lens review remains blocked at the authenticated CLI prerequisite; no reviewer model or clean skill result is claimed. Broader sampled-season HPO and optional/version coverage are not cleared by these tests. No earlier review was dismissed and no foreign thread was resolved. Final approval still requires all fresh same-head source, thread, Balanced Copilot and applicable contexts/actual workflows to succeed.
Posted by thinkall-agent-auto-reviewer
| if "are in both the seasonal and non-seasonal" not in str(e): | ||
| raise |
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
Reviewed the update from 3b13e2d493c6a24d34c206826b74a33cfd3f16cf to 523963dbe20bbfe4c93f42f538544bfa48d440b7. The new commit is the exact conflict-free automatic merge of current main f2427d802ae9ca23c2d99bef970373272afc5df1: only the two CI workflow files changed. The full automatic merge tree and exact parents were verified, with no manual resolution or contributor production/test changes. The main delta pins Python 3.12 for pre-commit and Java 17 for the applicable Ubuntu Spark jobs.
This bounded CI-only update inspection is not a fresh clean whole-feature independent review. Earlier scope findings, test qualifications and unresolved threads remain preserved. No earlier incomplete independent source review is promoted to clean by this CI merge.
No PR approval submitted. Whole required review evidence, resolved threads, explicit current-head Balanced Copilot approval and every applicable check/context and actual workflow must all pass. At this guarded readback, non-successful actual runs: [{"name": "Build", "status": "in_progress", "conclusion": null}, {"name": "Code formatting", "status": "completed", "conclusion": "failure"}]. No foreign thread was resolved and no earlier review was dismissed.
Posted by thinkall-agent-auto-reviewer
|
Two follow-ups in d454403: 1. Root-caused the failing 2. Copilot — the 2026-11-25 low-severity note about missing coverage for unrelated Local test run: |
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
The new unrelated-error test passes on Python 3.10 and 3.13, and current production correctly calls the statsmodels constructor only once for that error.
One remaining test-quality follow-up for the existing propagation discussion: the mock raises the same exception on every call, so the assertion also passes if the no-retry guard is removed and the constructor is called twice. I verified that with a process-local guard-removal mutation on both native stacks; no contributor code was changed.
Please bind the patch with as constructor and assert constructor.assert_called_once() after pytest.raises. This is a test-evidence gap, not a claim that current production retries. This review covers the new test delta and does not supersede the retained full-PR findings or clear unresolved threads.
Posted by thinkall-agent-auto-reviewer
|
Addressed in 3f13da8 — good catch on the mutation gap. The patch is now bound as |
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
The added constructor.assert_called_once() closes the previously reported no-retry test gap. The current regression passes on Python 3.10 and 3.13, and the skill-owned Low assertion-delta review is clean.
Production SARIMAX code is unchanged by these commits. This narrow clean result does not replace the retained full-PR review qualifications or resolve the remaining review threads. No prior review was dismissed.
Posted by thinkall-agent-auto-reviewer
|
Hi Li Jiang (@thinkall), thanks again for the detailed reviews. I believe all the reported issues are now addressed — the last follow-up (binding the unrelated-Error test with |
…ter successful retry
|
Thanks Li Jiang (@thinkall) — all three points from the 2026-12-01 review are addressed (plus Copilot's parametrized-coverage request):
Also added Local verification: |
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
New author correction only, reviewed at 60acd779dffe422449ab4ff61c468baf8e1163d3.
The no-op retry guard and delayed parameter publication pass ten selected checks plus four additional retry-fit/error-classification checks across both stacks. Real constructor errors and the retry protocol confirm unchanged orders after a failed fallback.
Low — strengthen the checked-in atomicity test (test/automl/test_forecast.py:1229-1266). The mixed-order case fails in retry construction, while the mocked fit failure occurs on the initial attempt. Add a case where retry construction succeeds but that retry's fit raises, then assert original reported orders. The independent case passes here and fails on the predecessor; the production correction works.
Low — make unrelated-error classification distinguishable from the no-op guard (test_forecast.py:1252-1268). With p=q=1 and s=4, clamping changes nothing. Use a residual clampable p=4 case and assert one construction call and unchanged orders; otherwise removing the message classification could still leave this test green. No new production defect was verified.
Independent Low review: 1/1 at the live maximum reasoning. Original findings, priorities and ISSUES_FOUND verdict are retained; these test/documentation notes are not a request to change working production behavior, and this COMMENT is not overall approval.
At 2026-12-03T11:44:17.902315+00:00, checks=PENDING; actual current-head workflows: Build=in_progress/None; Code formatting=completed/success; docs=completed/success. Workflow permission is not CI success. No contributor source was changed and no review outputs were pushed here.
Posted by thinkall-agent-auto-reviewer
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
Clean imported-base integration only, reviewed at 7741b90b6ee159c8e17e4f9a7b231c00d59d939d.
The new foreign SVC constructor change preserves explicit random_state (including None), consumes the random_seed alias, and retains clone/stacking behavior. The imported default forest classifier change leaves preprocessing to predict_proba, avoiding a second transformation while leaving regressor behavior unchanged. The selected tests pass14cases on each pinned stack (28for this head); the representative old-source controls fail26cases and pass2across stacks.
Exact merge-parent and changed-path checks show this is base alignment, not a new edit to this PR's original feature. The separate own-authored release README/docs/version paths were excluded from review. Independent Low coverage is1/1 at the live maximum reasoning, with a CLEAN verdict only for this imported-code scope. This does not resolve existing feature findings, active change requests, missing whole-PR evidence or prior safety stops, and is not overall PR approval.
All-files hooks passed for the retained local evidence commit. No contributor source was edited and no review outputs were pushed here.
At 2026-12-04T02:22:52.927435+00:00, checks=PENDING; actual current-head workflows: Code formatting=completed/success; Build=in_progress/None; docs=completed/success. Balanced Copilot approval recommendation=True; unresolved threads=2. Workflow permission is not CI success. Existing approval records, if retargeted by a base merge, are not a fresh whole-source or CI signoff.
Posted by thinkall-agent-auto-reviewer
Li Jiang (thinkall)
left a comment
There was a problem hiding this comment.
Imported FLOW2 integration only, reviewed at c10d8ad3bc2706bbf5c71ef0fc0907bf18e31c23.
The imported unordered categorical choice correction picks an index instead of allowing NumPy to coerce the choice values. Tuple/mixed choices, movement and seeded draws pass14cases on each pinned stack (28for this head). Exact merge/path proofs show no new feature-author edit in this branch. Existing branch-feature findings, active change requests and missing whole-PR coverage are not cleared by this new-base review.
Independent Low coverage1/1 at maximum reasoning; original CLEAN outcome is retained. This narrow verdict is not whole-PR code-review clearance and cannot reset prior safety/coverage bounds.
All-files hooks passed for the retained local evidence commit. Own-authored workflow/package-metadata changes were excluded; no contributor source was edited and no review outputs were pushed here.
At 2026-12-04T07:22:11.970204+00:00, checks=FAILURE; actual current-head workflows: Build=in_progress/None; Code formatting=completed/success; docs=completed/success. Balanced Copilot approval recommendation=True; unresolved threads=2. Workflow permission is not CI success.
Posted by thinkall-agent-auto-reviewer


Fixes #845
Problem
AutoML's
sarimaxlearner occasionally suggested configurations where a lag appears in both the seasonal and non-seasonal autoregressive or moving-average components. For example, the config from the issue ({"p": 4, "d": 0, "q": 5, "P": 1, "D": 3, "Q": 2, "s": 4}, e.g. via user-suppliedstarting_points) makes statsmodels raise:Non-seasonal AR lags are
{1..p}and seasonal AR lags are{s, 2s, ...}, so wheneverp >= s(withP > 0) lagsis duplicated. The same overlap exists on the MA side whenq >= swithQ > 0. The overlap can be injected by user-suppliedstarting_pointsor user-provided custom search spaces that bypass the built-in search-space bounds.Solution
1. Config clamping in
SARIMAX.config2params(flaml/automl/time_series/ts_model.py): the override calls the parent implementation, then, whens > 0, clampsptomax(0, s - 1)ifP > 0 and p >= s, and clampsqtomax(0, s - 1)ifQ > 0 and q >= s. This keeps every lag strictly below the first seasonal lag so no lag can be shared between the seasonal and non-seasonal polynomials, while leaving non-overlapping configs untouched.2. Defensive handling in
SARIMAX.fit(): model construction and fitting are wrapped in a targetedtry/except ValueError. Only the statsmodels overlapping-lag error (message containing"are in both the seasonal and non-seasonal") triggers the fallback; any otherValueErroris unrelated and propagates unchanged (nothing is silently hidden). On the fallback path a meaningful warning is logged describing the original order, the seasonal order and the error,self.paramsis updated to the actually-fitted (clamped) order so reported params are not misleading, and the model is refit once with the safe order.Tests
Added
test_sarimax_overlapping_lags_validation()intest/automl/test_forecast.py:p=4, q=5, P=1, Q=2, s=4— both AR and MA overlap) is clamped top=3, q=3and fits without the overlapping-lagValueError, producing a usable 6-step forecast;p>=s, P>0, Q=0) clampsponly; MA-only overlap (q>=s, Q>0, P=0) clampsqonly — both fit successfully;Actual results with
python -m pytest test/automl/test_forecast.py -k "sarimax" -q:(the warnings are pre-existing statsmodels
ValueWarning/ConvergenceWarningnotices on synthetic data)Additionally verified manually:
estimator_list=["sarimax"]with the invalidstarting_points) now completes:fit succeeded,best_estimator = sarimax;fit()fallback path handles invalid params injected after init and an unrelatedValueErrorstill propagates;