Repository navigation
TST: Cover the SARIMAX, VARMAX, DynamicFactor and UnobservedComponents models - #11083
Merged
Merged
Conversation
This was referenced Nov 23, 2026
Member
Author
|
Merge order. These open PRs build on this one (their branches contain its commits), so please merge this PR first:
Indented PRs build on the PR above them, so merge them after it. Once this PR is merged, their diffs shrink to their own changes. Each of them also says "Stacked on #..." at the top of its description. Merge-order note generated with Claude Code (updated 2026-11-25). |
This was referenced Nov 23, 2026
bashtage
force-pushed
the
wip-tsa-cov-c12
branch
from
November 24, 2026 16:16
8e9a185 to
8d30ba0
Compare
…s models
Add tests of the paths of statespace/sarimax.py, varmax.py,
dynamic_factor.py, structural.py and exponential_smoothing.py that the TSA
test suite did not reach, each checked against an independent value:
- SARIMAX: the Hamilton representation with differencing raises; simple
differencing of a series with an int64 index 0, ..., n - 1 (replaced by
a RangeIndex starting at one) or a RangeIndex, with the forecast index
continuing at nobs and the forecasts phi**h times the last difference;
initialize_default with an approximate diffuse variance v (the first
observation of an ARIMA(0, 1, 0) has variance v + sigma2); explosive
seasonal AR and non-invertible seasonal MA starting parameters warn and
start at zero; the variances of time-varying coefficients are named
snr.x with a concentrated scale, whose likelihood equals the likelihood
at the scaled variances; trend_offset in extend_kwargs of forecast (a
drift-only model in closed form); arfreq and mafreq (the roots of
1 -/+ 0.5 L, None without roots); the summary model name with lag lists.
- VARMAX: explosive AR and MA starting parameters warn and start at zero;
the starting measurement variances are the residual variances of the
VAR(1) of the data or of its residuals (numpy least squares); fixing MA
parameters (individual ones raise, all of them give the likelihood at
the full parameter vector, marked in the summary); model.simulate with
exog of the wrong shape raises; extending results without smoother
output continues the filter of the full sample; a simulation without
shocks from an anchor (also negative) is the dynamic prediction with
exog after the sample, and an anchor after the sample raises; summary
with separate_params=False; a univariate VARMAX is the SARIMAX AR(1).
- DynamicFactor: explosive factor (AR and VAR) and error VAR starting
parameters raise, or are explosive without enforce_stationarity; with
VAR errors the scalar starting variance is the mean of the diagonal
ones; fixing error transition parameters (all or none for VAR(1) and
AR(2) errors, individually for AR(1) errors) against the likelihood at
the full parameters; factors with filter and smoother output and
without factors; coefficients_of_determination are squared
correlations, shown by the bars of plot_coefficients_of_determination
with and without labels; summary with separate_params=False.
- UnobservedComponents: invalid frequency domain seasonals raise; the
default cycle bounds of annual, quarterly, monthly and daily data and
the starting cycle frequency; transform_params and untransform_params of
an undamped cycle in closed form; a model with only an AR(1) (no trend
specification) is the SARIMAX AR(1), also cloned; initialize_default
with an approximate diffuse variance (local level in closed form);
starting parameters ignore missing observations; deterministic
seasonal, frequency domain seasonal and cycle components (parameters
and summary); the component properties against the state vector at the
documented offsets with filter and smoother output, and the components
that are not in the model; plot_components without the observed panel
and without dates.
- ExponentialSmoothing: the known initial state of pandas data without
dates, and of numpy data in the summary.
Bugs found, not fixed here, which the tests avoid: the summary of a VARMAX
with measurement error shows the measurement variance of the last series
in the table of the first one (and so on); a bool level + trend
UnobservedComponents without stochastic level or trend has no trend
specification ("Model: None" in the summary; _mask_map has the key 8 for
"fixed slope" instead of 10); the starting parameters of an
UnobservedComponents without level are NaN with missing data; the cycle
frequency of annual data does not start at a three-year cycle on
pandas >= 2.2 (which is why the annual start is not checked);
time_varying_regression=True without exog removes the state error of a
SARIMAX.
Coverage of the five files by the TSA tests (not slow) goes from 98.0% to
99.5% of the lines and from 94.7% to 97.9% of the branches for
sarimax.py, 95.4% to 98.5% and 87.0% to 92.2% for varmax.py, 97.2% to
99.2% and 87.2% to 95.3% for dynamic_factor.py, 95.4% to 98.8% and 84.1%
to 97.5% for structural.py, and from 98.7% to 100% of the branches for
exponential_smoothing.py (100% of the lines before and after). The lines
left are unreachable through the public API or have no effect, are
reachable only through one of the bugs above, or (the annual start of the
cycle frequency) only on pandas < 2.2.
Fix the docstrings of statespace/sarimax.py, varmax.py, dynamic_factor.py, structural.py and exponential_smoothing.py where they disagree with the code. No code changes. - UnobservedComponents: without annual, quarterly or monthly data the default cycle periods are at least 2 (the frequency is at most pi), not 0.5; **kwargs are documented. plot_components shows confidence intervals only for the one-step-ahead predictions of the observed series (not for the components), has one panel per selected component (one per frequency domain seasonal) and returns the figure. The component properties return None for components that are not in the model (an empty list for freq_seasonal), their smoothed estimates are None without smoother output, and regression_coefficients is None (with an OutputWarning) if the coefficients are estimated by maximum likelihood. clone, update, initialize_default, transform_params and untransform_params get docstrings or their missing sections. - DynamicFactor: the parameters are listed in the order of the signature; endog needs more than one series and k_factors must be less than their number. update returns nothing, and its Notes describe the whole parameter vector (regression coefficients, the three error covariance types, error transitions) and the order of the factor VAR coefficients (by equation, not one coefficient matrix after another); the docstring is raw, so its \times no longer renders as a tab. transform_params also constrains the error transition and only with enforce_stationarity. factors is None without factors; coefficients_of_determination are from regressions of the series on a factor (smoothed if available); plot_coefficients_of_determination returns the figure. - VARMAX: order is a sequence of int with default (1, 0) (a generator raises); the Attributes no longer repeat the defaults of the parameters; the Notes of transform_params describe the VARMAX constraints, not a factor transition. - SARIMAX: the seasonal autoregressive polynomial attribute is no longer described as moving average; concentrate_scale defaults to False and missing lists its values. initialize_default, clone and SARIMAXResults.extend (which continues the time trend and skips the constant exog check) get docstrings; arfreq and mafreq are None without roots; update returns the transformed parameters including the fixed ones. - ExponentialSmoothing: initialization_method lists its values and refers to initial_trend (not initial_slope); bounds is a sequence (it is indexed); clone gets a docstring; ExponentialSmoothingResults documents its parameters and initial_state (an array, or a one-row DataFrame for pandas data). - All five results classes document their constructor parameters, specification is a Bunch, and the coefficient matrices of VARMAX and DynamicFactor results are None without the corresponding lags; transform_params and untransform_params return ndarrays.
bashtage
force-pushed
the
wip-tsa-cov-c12
branch
from
November 25, 2026 12:13
8d30ba0 to
4122c15
Compare
bashtage
marked this pull request as ready for review
November 25, 2026 16:08
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.
Only the docstrings of the five statespace model files (
sarimax.py,varmax.py,dynamic_factor.py,structural.py,exponential_smoothing.py) and their test files change. #10940 also adds a test totest_sarimax.py, at the end of the file; the SARIMAX tests here are inserted before the last test, so the two merge cleanly in any order. No other open PR changes these files.TST: Cover the SARIMAX, VARMAX, DynamicFactor and UnobservedComponents models
Add tests of the paths of statespace/sarimax.py, varmax.py,
dynamic_factor.py, structural.py and exponential_smoothing.py that the TSA
test suite did not reach, each checked against an independent value:
differencing of a series with an int64 index 0, ..., n - 1 (replaced by
a RangeIndex starting at one) or a RangeIndex, with the forecast index
continuing at nobs and the forecasts phi**h times the last difference;
initialize_default with an approximate diffuse variance v (the first
observation of an ARIMA(0, 1, 0) has variance v + sigma2); explosive
seasonal AR and non-invertible seasonal MA starting parameters warn and
start at zero; the variances of time-varying coefficients are named
snr.x with a concentrated scale, whose likelihood equals the likelihood
at the scaled variances; trend_offset in extend_kwargs of forecast (a
drift-only model in closed form); arfreq and mafreq (the roots of
1 -/+ 0.5 L, None without roots); the summary model name with lag lists.
the starting measurement variances are the residual variances of the
VAR(1) of the data or of its residuals (numpy least squares); fixing MA
parameters (individual ones raise, all of them give the likelihood at
the full parameter vector, marked in the summary); model.simulate with
exog of the wrong shape raises; extending results without smoother
output continues the filter of the full sample; a simulation without
shocks from an anchor (also negative) is the dynamic prediction with
exog after the sample, and an anchor after the sample raises; summary
with separate_params=False; a univariate VARMAX is the SARIMAX AR(1).
parameters raise, or are explosive without enforce_stationarity; with
VAR errors the scalar starting variance is the mean of the diagonal
ones; fixing error transition parameters (all or none for VAR(1) and
AR(2) errors, individually for AR(1) errors) against the likelihood at
the full parameters; factors with filter and smoother output and
without factors; coefficients_of_determination are squared
correlations, shown by the bars of plot_coefficients_of_determination
with and without labels; summary with separate_params=False.
default cycle bounds of annual, quarterly, monthly and daily data and
the starting cycle frequency; transform_params and untransform_params of
an undamped cycle in closed form; a model with only an AR(1) (no trend
specification) is the SARIMAX AR(1), also cloned; initialize_default
with an approximate diffuse variance (local level in closed form);
starting parameters ignore missing observations; deterministic
seasonal, frequency domain seasonal and cycle components (parameters
and summary); the component properties against the state vector at the
documented offsets with filter and smoother output, and the components
that are not in the model; plot_components without the observed panel
and without dates.
dates, and of numpy data in the summary.
Bugs found, not fixed here, which the tests avoid: the summary of a VARMAX
with measurement error shows the measurement variance of the last series
in the table of the first one (and so on); a bool level + trend
UnobservedComponents without stochastic level or trend has no trend
specification ("Model: None" in the summary; _mask_map has the key 8 for
"fixed slope" instead of 10); the starting parameters of an
UnobservedComponents without level are NaN with missing data; the cycle
frequency of annual data does not start at a three-year cycle on
pandas >= 2.2 (which is why the annual start is not checked);
time_varying_regression=True without exog removes the state error of a
SARIMAX.
Coverage of the five files by the TSA tests (not slow) goes from 98.0% to
99.5% of the lines and from 94.7% to 97.9% of the branches for
sarimax.py, 95.4% to 98.5% and 87.0% to 92.2% for varmax.py, 97.2% to
99.2% and 87.2% to 95.3% for dynamic_factor.py, 95.4% to 98.8% and 84.1%
to 97.5% for structural.py, and from 98.7% to 100% of the branches for
exponential_smoothing.py (100% of the lines before and after). The lines
left are unreachable through the public API or have no effect, are
reachable only through one of the bugs above, or (the annual start of the
cycle frequency) only on pandas < 2.2.
DOC: Correct the docstrings of the statespace models
Fix the docstrings of statespace/sarimax.py, varmax.py, dynamic_factor.py,
structural.py and exponential_smoothing.py where they disagree with the
code. No code changes.
UnobservedComponents: without annual, quarterly or monthly data the
default cycle periods are at least 2 (the frequency is at most pi), not
0.5; **kwargs are documented. plot_components shows confidence
intervals only for the one-step-ahead predictions of the observed series
(not for the components), has one panel per selected component (one per
frequency domain seasonal) and returns the figure. The component
properties return None for components that are not in the model (an
empty list for freq_seasonal), their smoothed estimates are None without
smoother output, and regression_coefficients is None (with an
OutputWarning) if the coefficients are estimated by maximum likelihood.
clone, update, initialize_default, transform_params and
untransform_params get docstrings or their missing sections.
DynamicFactor: the parameters are listed in the order of the signature;
endog needs more than one series and k_factors must be less than their
number. update returns nothing, and its Notes describe the whole
parameter vector (regression coefficients, the three error covariance
types, error transitions) and the order of the factor VAR coefficients
(by equation, not one coefficient matrix after another); the docstring
is raw, so its \times no longer renders as a tab. transform_params also
constrains the error transition and only with enforce_stationarity.
factors is None without factors; coefficients_of_determination are from
regressions of the series on a factor (smoothed if available);
plot_coefficients_of_determination returns the figure.
VARMAX: order is a sequence of int with default (1, 0) (a generator
raises); the Attributes no longer repeat the defaults of the
parameters; the Notes of transform_params describe the VARMAX
constraints, not a factor transition.
SARIMAX: the seasonal autoregressive polynomial attribute is no longer
described as moving average; concentrate_scale defaults to False and
missing lists its values. initialize_default, clone and
SARIMAXResults.extend (which continues the time trend and skips the
constant exog check) get docstrings; arfreq and mafreq are None without
roots; update returns the transformed parameters including the fixed
ones.
ExponentialSmoothing: initialization_method lists its values and refers
to initial_trend (not initial_slope); bounds is a sequence (it is
indexed); clone gets a docstring; ExponentialSmoothingResults documents
its parameters and initial_state (an array, or a one-row DataFrame for
pandas data).
All five results classes document their constructor parameters,
specification is a Bunch, and the coefficient matrices of VARMAX and
DynamicFactor results are None without the corresponding lags;
transform_params and untransform_params return ndarrays.
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: auditing the coverage gaps and the docstrings of the five state space models against the code, writing the tests (checked against closed forms, equivalent models such as SARIMAX against VARMAX and UnobservedComponents, least squares computed with numpy, and refits at fixed parameters) and the docstring fixes, and checking them (coverage before and after, mutation check of the newly covered lines).
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