Repository navigation
BUG: Input checks for ETSModel and ETS get_prediction - #10937
Merged
Merged
Conversation
bashtage
force-pushed
the
wip-ets-input-checks
branch
from
November 21, 2026 21:40
ded07f4 to
a0f1769
Compare
4 of 5 tasks
bashtage
force-pushed
the
wip-ets-input-checks
branch
7 times, most recently
from
November 25, 2026 18:38
18449e9 to
b416e5f
Compare
`ETSResults.get_prediction(method=...)` and `PredictionResults` document `method` as "exact", "simulated" or None, but accepted any value and treated everything other than "simulated" as "exact", silently: `method="foo"`, `method=1` and also `method="Simulated"` (capital S) returned the exact prediction intervals. Changes: - A `method` other than "exact", "simulated" or None (checked with `string_like`, case-sensitively) issues a FutureWarning: 'method must be "exact", "simulated" or None, got 'foo'. Other values are treated as "exact". This is deprecated and will raise a ValueError after statsmodels 0.17 is released.' The value is still treated as "exact" and stored as given in `method`, so the results do not change. A ValueError right away would break code that ran, so this is a deprecation. - `deprecated` notes on `method` of `get_prediction` and `PredictionResults`. Results do not change for any value of `method`. Tests: `test_get_prediction_unknown_method` checks the warning (and that it points at the caller) and that "foo", "Simulated", "EXACT" and 1 give the exact intervals, and `test_get_prediction_known_method_no_warning` that None, "exact" and "simulated" do not warn. The four unknown values fail on main.
`ETSModel` documents `endog` as array_like, but an (nobs, 1) array or a one-column DataFrame raised "ValueError: endog must be 1-dimensional". Other statsmodels models and the data handling of the base model accept a single column as the series (the model's `data.endog` and names are already those of the series). Changes: - `ETSModel.prepare_data` uses the column of a two-dimensional `endog` with one column. Input with more than one column, or a (1, nobs) row, raises the same ValueError as before. - The conversion of integer data to float uses that 1-D array. It used the original data, which would have been 2-D again. - A `versionchanged` note on `endog`. Results of 1-D input do not change. Tests: `test_endog_single_column` compares the start parameters, the log-likelihood, the fitted values and the forecasts of a one-column DataFrame, an (nobs, 1) float array and an (nobs, 1) integer array with those of the 1-D data, and the forecast index and the prediction summary frame for the DataFrame; `test_endog_not_single_column` checks that two columns and a row still raise. The three single-column cases fail on main.
A seasonal `ETSModel` without `seasonal_periods` infers it from the
frequency of the date index of `endog`. Without such a frequency (numpy
data, a RangeIndex, or dates without a frequency) it raised a bare
`AssertionError` from `freq_to_period(None)`:
ETSModel(y, seasonal="add")
# AssertionError
Changes:
- This raises "ValueError: seasonal_periods must be given for a seasonal
model if endog has no date index with a frequency."
Only input that raised is affected; models with `seasonal_periods` or
with a date frequency are unchanged.
Tests: `test_seasonal_periods_required` checks the error for numpy data,
a Series with a RangeIndex and a Series with irregular dates, for
additive and multiplicative seasonality. All six cases fail on main
(AssertionError).
With `initialization_method="known"`, `initial_seasonal` is documented as
"an array of length seasonal_periods", but its length was not checked:
- a scalar or a single value (`[5.0]`, a (1, 1) array) was broadcast
silently to all seasonal states;
- other lengths, an (m, 1) column and a 0-d array were accepted by the
constructor and failed later, when the model was smoothed or fit, with
a NumPy error ("could not broadcast input array from shape (2,) into
shape (4,)", or an IndexError for a 0-d array);
- a (1, m) row was used with its seasonal states in reverse order,
silently, as the reversal of the internal parameter vector only
reversed its first axis.
Changes:
- A single value issues a FutureWarning: "initial_seasonal has a single
value, which is used for all 4 initial seasonal states. This is
deprecated and will raise a ValueError after statsmodels 0.17 is
released. Pass an array of length seasonal_periods instead." The value
is still broadcast, so the results do not change. It ran, so this is a
deprecation rather than an error.
- Any other shape than (seasonal_periods,) raises "ValueError:
initial_seasonal must have length seasonal_periods (4), got an array
of shape (2,)." in the constructor (and in
`set_initialization_method`). This includes the (1, m) row, which gave
a silently wrong model.
- `deprecated` notes on `initial_seasonal` of `ETSModel` and
`set_initialization_method`.
Results of an `initial_seasonal` of length seasonal_periods (a list, a
tuple, an ndarray or a Series) and of a single value do not change.
Tests: `test_initial_seasonal_single_value` checks the warning and
compares a list, a float, a np.float64 and a (1, 1) array with the
explicitly repeated value; `test_initial_seasonal_wrong_length` checks
the error for lengths 2 and 5, a column, a row and a 0-d array; and
`test_initial_seasonal_forms` that the valid forms do not warn and give
the documented order (the first prediction uses the first value). The
nine warning and error cases fail on main.
…odel A known initial_seasonal given as a (1, seasonal_periods) row ran, but its seasonal states were used in reverse order, and an (seasonal_periods, 1) column raised a numpy error when the model was used. The previous commit made both raise a ValueError. A single row or column is now used as the 1-d array, as a single column endog is, so the row gives the results of the same values as a list: they change from the reversed order. Other shapes still raise. The test compares a row and a column with the list of the same values.
Since statsmodels#10975 merged, ETSModel.fit, fit_constrained and smooth warn when param_index is not given (the default changes from "integer" to "names" after statsmodels 0.17). The tests this PR adds called them without it, so they leaked that FutureWarning. Pass param_index="integer", as the existing tests do; results are unchanged.
bashtage
force-pushed
the
wip-ets-input-checks
branch
from
November 27, 2026 00:30
b416e5f to
71f888f
Compare
bashtage
marked this pull request as ready for review
November 27, 2026 21:36
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.
Five input checks of
ETSModelandget_prediction, one commit each. The details are in each commit.DEP: Deprecate unknown method values in ETS get_prediction
ETSResults.get_prediction(method=...)andPredictionResultsdocumentmethodas "exact", "simulated" or None, but accepted any value andtreated everything other than "simulated" as "exact", silently:
method="foo",method=1and alsomethod="Simulated"(capital S)returned the exact prediction intervals.
Changes:
methodother than "exact", "simulated" or None (checked withstring_like, case-sensitively) issues a FutureWarning: 'method mustbe "exact", "simulated" or None, got 'foo'. Other values are treated as
"exact". This is deprecated and will raise a ValueError after
statsmodels 0.17 is released.' The value is still treated as "exact"
and stored as given in
method, so the results do not change. AValueError right away would break code that ran, so this is a
deprecation.
deprecatednotes onmethodofget_predictionandPredictionResults.Results do not change for any value of
method.Tests:
test_get_prediction_unknown_methodchecks the warning (and thatit points at the caller) and that "foo", "Simulated", "EXACT" and 1 give
the exact intervals, and
test_get_prediction_known_method_no_warningthat None, "exact" and "simulated" do not warn. The four unknown values
fail on main.
BUG: Accept a single column as endog in ETSModel
ETSModeldocumentsendogas array_like, but an (nobs, 1) array or aone-column DataFrame raised "ValueError: endog must be 1-dimensional".
Other statsmodels models and the data handling of the base model accept
a single column as the series (the model's
data.endogand names arealready those of the series).
Changes:
ETSModel.prepare_datauses the column of a two-dimensionalendogwith one column. Input with more than one column, or a (1, nobs) row,
raises the same ValueError as before.
the original data, which would have been 2-D again.
versionchangednote onendog.Results of 1-D input do not change.
Tests:
test_endog_single_columncompares the start parameters, thelog-likelihood, the fitted values and the forecasts of a one-column
DataFrame, an (nobs, 1) float array and an (nobs, 1) integer array with
those of the 1-D data, and the forecast index and the prediction summary
frame for the DataFrame;
test_endog_not_single_columnchecks that twocolumns and a row still raise. The three single-column cases fail on
main.
BUG: Raise a ValueError when ETSModel cannot infer seasonal_periods
A seasonal
ETSModelwithoutseasonal_periodsinfers it from thefrequency of the date index of
endog. Without such a frequency (numpydata, a RangeIndex, or dates without a frequency) it raised a bare
AssertionErrorfromfreq_to_period(None):Changes:
model if endog has no date index with a frequency."
Only input that raised is affected; models with
seasonal_periodsorwith a date frequency are unchanged.
Tests:
test_seasonal_periods_requiredchecks the error for numpy data,a Series with a RangeIndex and a Series with irregular dates, for
additive and multiplicative seasonality. All six cases fail on main
(AssertionError).
DEP: Check the length of a known initial_seasonal in ETSModel
With
initialization_method="known",initial_seasonalis documented as"an array of length seasonal_periods", but its length was not checked:
[5.0], a (1, 1) array) was broadcastsilently to all seasonal states;
constructor and failed later, when the model was smoothed or fit, with
a NumPy error ("could not broadcast input array from shape (2,) into
shape (4,)", or an IndexError for a 0-d array);
silently, as the reversal of the internal parameter vector only
reversed its first axis.
Changes:
value, which is used for all 4 initial seasonal states. This is
deprecated and will raise a ValueError after statsmodels 0.17 is
released. Pass an array of length seasonal_periods instead." The value
is still broadcast, so the results do not change. It ran, so this is a
deprecation rather than an error.
initial_seasonal must have length seasonal_periods (4), got an array
of shape (2,)." in the constructor (and in
set_initialization_method). This includes the (1, m) row, which gavea silently wrong model.
deprecatednotes oninitial_seasonalofETSModelandset_initialization_method.Results of an
initial_seasonalof length seasonal_periods (a list, atuple, an ndarray or a Series) and of a single value do not change.
Tests:
test_initial_seasonal_single_valuechecks the warning andcompares a list, a float, a np.float64 and a (1, 1) array with the
explicitly repeated value;
test_initial_seasonal_wrong_lengthchecksthe error for lengths 2 and 5, a column, a row and a 0-d array; and
test_initial_seasonal_formsthat the valid forms do not warn and givethe documented order (the first prediction uses the first value). The
nine warning and error cases fail on main.
BUG: Use a single row or column as the known initial_seasonal of ETSModel
A known initial_seasonal given as a (1, seasonal_periods) row ran, but its seasonal states were used in reverse order, and an (seasonal_periods, 1) column raised a numpy error when the model was used. The previous commit made both raise a ValueError. A single row or column is now used as the 1-d array, as a single column endog is, so the row gives the results of the same values as a list: they change from the reversed order. Other shapes still raise.
The test compares a row and a column with the list of the same values.
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 contract audit, 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