Repository navigation
Conversation
This was referenced Nov 23, 2026
bashtage
force-pushed
the
wip-uc-annual-cycle-start
branch
4 times, most recently
from
November 25, 2026 18:40
ba19c2e to
8da3bed
Compare
4 of 5 tasks
UnobservedComponents.start_params drops missing observations before it computes the starting parameters, but a model without a level used the full series from the state space representation, NaN included, for the remaining components. With missing data: - UnobservedComponents(y, "irregular", seasonal=4) (or a frequency-domain seasonal) had start_params [nan, nan], so fit() returned NaN parameters and a NaN log-likelihood with only a ConvergenceWarning; - "ntrend" with autoregressive=1, and a damped stochastic cycle, raised "LinAlgError: SVD did not converge"; - an exog (estimated by maximum likelihood) raised "ValueError: shapes (1,38) and (40,) not aligned", because exog had the missing rows dropped and the series did not. Changes - Without a level, the residual used for the other components is the series with the missing observations dropped, as with a level. The starting parameters are those of the model of the data without the missing observations, so fit() starts from finite values. - start_params has a docstring, with a versionchanged note. Not changed - The starting parameters of models without missing data (identical, bit for bit, for int and float data, ndarray, list and Series, with seasonal, frequency-domain seasonal, autoregressive, cycle and exog components) and of models with a level. Tests - Without a level, with three missing observations, for a seasonal, a frequency-domain seasonal, an AR(1), a damped stochastic cycle, an exog, and an exog with an AR(1) without irregular: the starting parameters equal those of the same model of the data without the missing observations; for the two seasonal models, every variance starts at the variance of the observed data and fit() gives finite parameters and log-likelihood. All six fail on main.
…eriod
For annual data, the default bounds of the cycle period of
UnobservedComponents are 1.5 to 12 years, and the frequency of the cycle
should start at that of a three-year cycle (2 pi / 3), as it does at
twelve quarters and 36 months for quarterly and monthly data. The bounds
check the first letter of the frequency string for "A" or "Y", but the
start checked only "A", the annual frequency strings before pandas 2.2.
From pandas 2.2 they start with "Y" ("YS-JAN", "YE-DEC", "Y-DEC" for a
PeriodIndex), so the frequency started in the middle of the bounds,
2.356 instead of 2.094 for a local level with a stochastic cycle on
annual data, which changes the fit as well. The bounds were updated for the
new strings in 929a99a; the start was missed.
Changes
- The cycle frequency starts at 2 pi / 3 for annual data with either
first letter, as the bounds do, so starting parameters and fits of models
with a cycle on annual data change on pandas 2.2 and later.
- A versionchanged note in the docstring of start_params.
Not changed
- Results on pandas before 2.2, and for quarterly, monthly and other data.
- The bounds of the cycle frequency.
Tests
- For annual data (year end, year start in July, year end in June, and an
annual PeriodIndex, built with offsets so that the test runs on every
supported pandas), the bounds are 2 pi / 12 to 2 pi / 1.5 and the start
is 2 pi / 3. All four fail on main with pandas 3.0.5 and 2.3.3.
- test_cycle_frequency_bounds checks the annual start too; it skipped it
because the start depended on the pandas version.
bashtage
force-pushed
the
wip-uc-annual-cycle-start
branch
from
November 28, 2026 21:36
8da3bed to
b137b85
Compare
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.
Stacked on #11087, merge that first (this PR adds one commit). The fixed-slope PR also appends tests to
test_structural.py: keep both appended blocks. No conflict instructural.pyor with #10940.BUG: Drop missing data from the start params of UnobservedComponents
UnobservedComponents.start_params drops missing observations before it
computes the starting parameters, but a model without a level used the
full series from the state space representation, NaN included, for the
remaining components. With missing data:
seasonal) had start_params [nan, nan], so fit() returned NaN parameters
and a NaN log-likelihood with only a ConvergenceWarning;
"LinAlgError: SVD did not converge";
(1,38) and (40,) not aligned", because exog had the missing rows dropped
and the series did not.
Changes
series with the missing observations dropped, as with a level. The
starting parameters are those of the model of the data without the
missing observations, so fit() starts from finite values.
Not changed
for bit, for int and float data, ndarray, list and Series, with seasonal,
frequency-domain seasonal, autoregressive, cycle and exog components) and
of models with a level.
Tests
frequency-domain seasonal, an AR(1), a damped stochastic cycle, an exog,
and an exog with an AR(1) without irregular: the starting parameters
equal those of the same model of the data without the missing
observations; for the two seasonal models, every variance starts at the
variance of the observed data and fit() gives finite parameters and
log-likelihood. All six fail on main.
BUG: Start the annual cycle of UnobservedComponents at a three-year period
For annual data, the default bounds of the cycle period of
UnobservedComponents are 1.5 to 12 years, and the frequency of the cycle
should start at that of a three-year cycle (2 pi / 3), as it does at
twelve quarters and 36 months for quarterly and monthly data. The bounds
check the first letter of the frequency string for "A" or "Y", but the
start checked only "A", the annual frequency strings before pandas 2.2.
From pandas 2.2 they start with "Y" ("YS-JAN", "YE-DEC", "Y-DEC" for a
PeriodIndex), so the frequency started in the middle of the bounds,
2.356 instead of 2.094 for a local level with a stochastic cycle on
annual data, which changes the fit as well. The bounds were updated for the
new strings in 929a99a; the start was missed.
Changes
first letter, as the bounds do, so starting parameters and fits of models
with a cycle on annual data change on pandas 2.2 and later.
Not changed
Tests
For annual data (year end, year start in July, year end in June, and an
annual PeriodIndex, built with offsets so that the test runs on every
supported pandas), the bounds are 2 pi / 12 to 2 pi / 1.5 and the start
is 2 pi / 3. All four fail on main with pandas 3.0.5 and 2.3.3.
test_cycle_frequency_bounds checks the annual start too; it skipped it
because the start depended on the pandas version.
tests added / passed.
code/documentation is well formatted.
properly formatted commit message. See
NumPy's guide.
AI Disclosure
Contributions must comply with the statsmodels AI Policy.
Tick exactly one of the following. If AI tools were used, replace the
<...>placeholders in the second option with the tool name(s) and how the tool's output was
used.
Tool(s): Claude Code (Claude Opus 5.5).
Used for: finding the bug in a coverage audit of the state space models, writing the fix and its tests, and checking them (tests failing on main, mutation check).
I have personally read, understood, and can explain every line of this diff, and
have verified the statistical/numerical correctness of the change.
🤖 Generated with Claude Code