Exceptions and warnings¶
Errors and warnings raised by skforecast_ai. All of them are importable from the package root, for example from skforecast_ai import LLMCallError.
Every error derives from SkforecastAIError, which carries a code from a closed set, the argument at fault in field (None when the error is not tied to one) and an optional remedy in hint, which is not part of str(exc). A program can react to code and field without parsing the message. The errors for invalid inputs also derive from the built-in exception raised before 0.4.0 (ValueError, TypeError or FileNotFoundError), so existing except clauses keep catching them with the same message.
| Name | Raised or warned by | When |
|---|---|---|
SkforecastAIError |
every method | Base class of the errors below. Catch it to handle any error of skforecast-ai. |
InvalidInputError |
every method | An argument, or the plan, profile or CV passed in, is not valid. A ValueError. |
InvalidInputTypeError |
every method | An argument has a type that is not accepted, such as a bool test_size or a compare() candidate config that is not a dict, or a CVResult is unpacked as a tuple. A TypeError, and also an InvalidInputError and therefore a ValueError. |
DataContentError |
forecast(), backtest(), compare() and the CLI |
Every argument is valid and the content of the data, or of the future exogenous variables, cannot be used for what was asked: a missing value of the target that a prediction or a metric reads, a training window whose rows all read one, a missing exogenous value of the data that a prediction of backtest() reads, final rows without a target value, or future exogenous variables whose columns, dates or values do not fit the data and the plan. An InvalidInputError and therefore a ValueError, with the same code and field. |
CostNotConfirmedError |
backtest(), compare() and the CLI |
The run is expensive (above 50 estimator fits, or 2000 inference windows of a foundation model; for compare(), all its candidates together) and confirm_cost does not confirm it. Raised before anything runs: in backtest() after its other checks, in compare() once the plans of the candidates are built; the message states the cost and the changes that lower it. Pass confirm_cost=True (--confirm-cost in the CLI) to run it as it is. figure, cost and comparison_cost hold the cost. An InvalidInputError with the field confirm_cost. |
DataNotFoundError |
every method that takes data, and the CLI |
The CSV path does not exist or the URL cannot be read, or a JSON or CSV input of the CLI does not exist. A FileNotFoundError. |
LLMRequiredError |
ask(), refine_plan() and create_cv() with a prompt |
The method needs an LLM and none was configured at init time. |
LLMCallError |
ask() |
The call to the LLM fails. There is no deterministic answer to fall back on, so the provider error is raised (chained as original_error) instead of returned as text. |
ForecastExecutionError |
forecast(), backtest() |
The generated script does not compile or fails while running. The script and the full traceback are available as generated_code and execution_traceback, and the line and the statement that failed as failed_line and failed_statement. |
AllCandidatesFailedError |
compare() |
Every candidate configuration fails, so there is no leaderboard to return. The per-candidate reasons are in failures. |
CandidateFailedWarning |
compare() |
One candidate fails; the comparison continues with the rest and the failure is recorded in ComparisonResult.failures. |
MissingBackendWarning |
compare() without candidates, plan() |
The backend of the default foundation model (chronos-forecasting for Chronos-2) is not installed, so ForecasterFoundation is left out of the comparison instead of failing; install it with pip install skforecast-ai[foundation]. With several series, XGBRegressor is left out the same way when xgboost, which no extra installs, is missing. plan() warns when the estimator of the plan (XGBoost, CatBoost) is not installed: the plan is made, since its script may run elsewhere, and running it here fails with missing_dependency. |
IntervalCoverageWarning |
backtest(), compare() with interval |
The prediction interval covers clearly less than its nominal level (upper - lower) in a series: the coverage that skforecast measured is more than two binomial standard errors for the number of predictions, and at least 5 percentage points, below it. It names the series (in compare(), the candidates) with their coverage; report that coverage, not the nominal level. The summary of the backtest gives the coverage and the mean width of the interval of every series. |
FoldsLeftOutWarning |
backtest(), compare() of several series |
The backtest did not forecast a series in some test folds where it has values to evaluate (one that starts late, with refit, say), so its metrics, and the average across series, use fewer folds than the others. Read from the level and fold of the predictions; it names the series (in compare(), the candidates) with those folds, as the explanation does. A series that no fold forecasts raises InvalidInputError before running instead. |
DataSentToLLMWarning |
ask() |
A result with values of its own (predictions, metrics) is sent to the LLM while send_data_to_llm=False. Pass send_data_to_llm=True to acknowledge it. |
PlanEditsDiscardedWarning |
refine_plan(), compare() without candidates |
The plan holds values edited by hand (a key of forecaster_kwargs, the preprocessing steps) that the refined plan does not keep. The warning names them and its text is kept in the warnings of the refined plan. The ones refine_plan() takes as overrides (forecaster, lags, metric...) can be passed again; the others cannot be kept. It also names the decisions the refined plan leaves out because its forecaster or estimator cannot take them (the estimator_kwargs of another estimator; the differentiation, calendar features, target transformer, lags refined by the LLM, or the transformer_exog and categorical_features of the exogenous columns the plan read, when switching to ForecasterStats, ForecasterFoundation or the baseline), and whether the user, the LLM or the rules chose them, in the same warning as the values edited by hand. In compare(), the row 'Strategy plan' runs the plan of the CVResult without them: backtest() measures it as it is. |
UnrecommendedForecasterWarning |
plan() |
The requested forecaster is supported but was not among the profile's candidates for this dataset (for example, Auto-ARIMA on high-frequency data). |
refine_plan() and create_cv() do not raise when the LLM fails: they emit a UserWarning and return their deterministic result, which is valid on its own.
The warnings that skforecast emits while forecast(), backtest() and compare() run the generated script (for example MissingValuesWarning) are shown when the script ends, after its printed output is discarded. Your warning filters apply as usual: warnings.simplefilter('ignore', category=...) hides them, and an error filter makes the script fail.
Error codes¶
code |
Raised as | When |
|---|---|---|
invalid_argument |
InvalidInputError, InvalidInputTypeError, DataContentError |
An argument or a received object is not valid. |
insufficient_data |
InvalidInputError |
The data is too short for what was asked: fewer than two folds for the cross-validation, lags and window features longer than the data allows, a target column without any value, or a series of ForecasterRecursiveMultiSeries without values or shorter than its lags and window features. |
data_not_found |
DataNotFoundError |
A file to read (the CSV path or URL, or an input of the CLI) cannot be found. |
data_unreadable |
DataNotFoundError, InvalidInputError |
An input exists but cannot be parsed: a CSV file that pandas cannot read (empty, binary, in UTF-16 or in another encoding than UTF-8 and cp1252, rows with more fields than the header, or a column without name and values) or whose separator, decimal mark or thousands separator cannot be told (pass sep, decimal or thousands to profile()) or whose dates read both day first and month first with nothing to tell the order (pass dayfirst; for the file of future exogenous values, write its dates in ISO 8601), a URL whose content is not a CSV (DataNotFoundError, as before), or the JSON of --from-plan or --from-profile in the CLI. |
missing_dependency |
InvalidInputError |
The package of the chosen estimator, or the backend package of the foundation model, is not installed. Checked before forecast() and backtest() run the script; plan() already warns about an estimator with MissingBackendWarning. |
execution_failed |
ForecastExecutionError |
The generated script fails. |
all_candidates_failed |
AllCandidatesFailedError |
Every candidate of compare() fails. |
llm_required |
LLMRequiredError |
The method needs an LLM and none is configured. |
llm_call_failed |
LLMCallError |
The call to the LLM fails. |
internal_error |
Not raised by skforecast-ai: ErrorInfo uses it for any exception that skforecast-ai did not raise itself (it is also the default code of a bare SkforecastAIError). |
Some errors carry a remedy in hint that does not depend on Python, for a program or an agent that passes paths (the CLI prints it as a tip): for example how to write the dates, or what a CSV file that cannot be read must look like. Messages that suggest a pandas call keep it, and hint gives the remedy without it.
ErrorInfo.from_exception(), in skforecast_ai.schemas, turns an exception into plain data (code, message, field, hint) for a reader outside Python: it never holds a traceback or generated code, takes the field of a pydantic ValidationError from the location of its first error, and describes any other exception by its type and the first line of its message.
skforecast_ai.exceptions ¶
Classes:
| Name | Description |
|---|---|
SkforecastAIError |
Base class of the errors raised by skforecast-ai. |
InvalidInputError |
Raised when an argument, or the plan, profile or CV passed in, is not |
InvalidInputTypeError |
Raised when an argument has a type that is not accepted. |
DataContentError |
Raised when the content of the data, or of the future exogenous |
CostNotConfirmedError |
Raised by |
DataNotFoundError |
Raised when a file to read cannot be found: the data (a CSV path or |
LLMRequiredError |
Raised when a method that requires an LLM is called without one. |
LLMCallError |
Raised by |
ForecastExecutionError |
Raised when the generated forecasting code fails to compile or fails |
AllCandidatesFailedError |
Raised by |
CandidateFailedWarning |
Warned by |
DataSentToLLMWarning |
Warned when data values are sent to the LLM against |
FoldsLeftOutWarning |
Warned by |
IntervalCoverageWarning |
Warned by |
MissingBackendWarning |
Warned when a model needs a package that is not installed: by |
PlanEditsDiscardedWarning |
Warned by |
UnrecommendedForecasterWarning |
Warned by |
Attributes:
| Name | Type | Description |
|---|---|---|
ErrorCode |
Closed set of codes carried by |
|
ERROR_CODES |
tuple[str, ...]
|
|
Attributes¶
ErrorCode
module-attribute
¶
ErrorCode = Literal[
"invalid_argument",
"insufficient_data",
"data_not_found",
"data_unreadable",
"missing_dependency",
"execution_failed",
"all_candidates_failed",
"llm_required",
"llm_call_failed",
"internal_error",
]
Closed set of codes carried by SkforecastAIError.code.
Classes¶
SkforecastAIError ¶
SkforecastAIError(
message="", *, code=None, field=None, hint=None
)
Bases: Exception
Base class of the errors raised by skforecast-ai.
Every error carries a stable code from a closed set and, when one
argument is at fault, its name in field, so a program (an agent, the
CLI) can react to the kind of error without parsing the message. The
message is the text of the exception; hint is an optional remedy kept
out of it, so str(exc) is the message alone.
Each subclass also derives from the built-in exception that was raised
before the hierarchy existed (ValueError, TypeError,
FileNotFoundError), so existing except clauses keep catching it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error message, returned by |
''
|
code
|
str
|
One of |
None
|
field
|
str
|
Name of the argument (or the field of a plan, profile or CV) at fault. None when the error is not tied to a single argument. |
None
|
hint
|
str
|
Optional remedy, not part of |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
code |
str
|
One of |
field |
(str, None)
|
Name of the argument at fault. |
hint |
(str, None)
|
Optional remedy. |
Source code in skforecast_ai/exceptions.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
InvalidInputError ¶
InvalidInputError(
message="", *, code=None, field=None, hint=None
)
Bases: SkforecastAIError, ValueError
Raised when an argument, or the plan, profile or CV passed in, is not valid.
A subclass of ValueError, the class raised for these errors before
skforecast-ai had its own hierarchy. The default code is
'invalid_argument'; errors caused by too little data use
'insufficient_data', and a missing optional package
'missing_dependency'.
Attributes:
| Name | Type | Description |
|---|---|---|
default_code |
ErrorCode
|
|
Source code in skforecast_ai/exceptions.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
InvalidInputTypeError ¶
InvalidInputTypeError(
message="", *, code=None, field=None, hint=None
)
Bases: InvalidInputError, TypeError
Raised when an argument has a type that is not accepted.
A subclass of TypeError, the class raised for these errors before
skforecast-ai had its own hierarchy, and of InvalidInputError, so
catching InvalidInputError covers every invalid input.
Source code in skforecast_ai/exceptions.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
DataContentError ¶
DataContentError(
message="", *, code=None, field=None, hint=None
)
Bases: InvalidInputError
Raised when the content of the data, or of the future exogenous variables, cannot be used for what was asked, although every argument is valid: a missing value of the target that a prediction or a metric reads, final rows without a target value, or future exogenous variables whose columns, dates or values do not fit the data and the plan.
A subclass of InvalidInputError, with its code and its field
('data', 'exog' or 'test_size'), so catching InvalidInputError
or ValueError still covers it. Catch it to tell a problem of the
values, which is solved in the data, from an argument to correct.
Source code in skforecast_ai/exceptions.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
CostNotConfirmedError ¶
CostNotConfirmedError(
message,
*,
figure,
cost,
description,
comparison_cost=None,
hint=None
)
Bases: InvalidInputError
Raised by backtest() and compare() before anything runs when the
run is above the thresholds of an expensive run (50 estimator fits or
2000 inference windows of a foundation model; for a comparison, all
its candidates together) and confirm_cost does not confirm it.
The message states the cost, what makes it and the changes that lower
it; hint says how to run it as it is. A subclass of
InvalidInputError, with the code 'invalid_argument' and the field
'confirm_cost'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error message, returned by |
required |
figure
|
int
|
Number that confirms the run, see the attribute. |
required |
cost
|
dict
|
Cost of the run, see the attribute. |
required |
description
|
str
|
Sentence stating the cost, see the attribute. |
required |
comparison_cost
|
ComparisonCost
|
Cost of each candidate of a comparison. |
None
|
hint
|
str
|
How to run it as it is. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
figure |
int
|
Number that confirms the run as |
cost |
dict
|
|
description |
str
|
Sentence stating the cost and what makes it, without how to lower it or how to confirm it. |
comparison_cost |
(ComparisonCost, None)
|
Cost of each candidate of a comparison, None for a backtest. |
Source code in skforecast_ai/exceptions.py
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
DataNotFoundError ¶
DataNotFoundError(
message="", *, code=None, field=None, hint=None
)
Bases: SkforecastAIError, FileNotFoundError
Raised when a file to read cannot be found: the data (a CSV path or URL), or a JSON or CSV input of the CLI.
A subclass of FileNotFoundError, the class raised for these errors
before skforecast-ai had its own hierarchy. The code is
'data_not_found'.
Attributes:
| Name | Type | Description |
|---|---|---|
default_code |
ErrorCode
|
|
Source code in skforecast_ai/exceptions.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
LLMRequiredError ¶
LLMRequiredError(method_name)
Bases: SkforecastAIError
Raised when a method that requires an LLM is called without one.
The code is 'llm_required'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method_name
|
str
|
Name of the method that requires an LLM. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
default_code |
ErrorCode
|
|
Source code in skforecast_ai/exceptions.py
216 217 218 219 220 | |
LLMCallError ¶
LLMCallError(llm, original_error)
Bases: SkforecastAIError
Raised by ask() when the call to the LLM fails.
ask() has no deterministic answer to fall back on, so a failed call
(network, authentication, provider error, or a local model that is
not reachable) is reported as an error instead of a result whose
explanation is not an answer. The original exception is chained and
kept as an attribute. The code is 'llm_call_failed'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
llm
|
str
|
LLM provider string in format |
required |
original_error
|
Exception
|
The exception raised by the provider or the agent. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
llm |
str
|
LLM provider string in format |
original_error |
Exception
|
The exception raised by the provider or the agent. |
Source code in skforecast_ai/exceptions.py
250 251 252 253 254 255 256 257 258 259 260 | |
ForecastExecutionError ¶
ForecastExecutionError(
original_error,
generated_code,
execution_traceback,
failed_line=None,
failed_statement=None,
)
Bases: SkforecastAIError
Raised when the generated forecasting code fails to compile or fails during exec().
The short message surfaces the original error. The full generated
code and traceback are available as attributes for debugging, together
with the line and the statement of the generated code that failed. The
code is 'execution_failed'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_error
|
Exception
|
The exception raised while compiling or executing the code. |
required |
generated_code
|
str
|
The generated Python code that was executed. |
required |
execution_traceback
|
str
|
The full formatted traceback from execution. |
required |
failed_line
|
int
|
Line of |
None
|
failed_statement
|
str
|
Source of the statement of |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
original_error |
Exception
|
The exception raised while compiling or executing the code. |
generated_code |
str
|
The generated Python code that was executed. |
execution_traceback |
str
|
The full formatted traceback from execution. |
failed_line |
(int, None)
|
Line of |
failed_statement |
(str, None)
|
Source of the statement of |
Source code in skforecast_ai/exceptions.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
Attributes¶
AllCandidatesFailedError ¶
AllCandidatesFailedError(failures)
Bases: SkforecastAIError
Raised by compare() when every candidate configuration fails.
A comparison with zero successful candidates has no leaderboard and
no winner, so it is reported as a failure instead of returning a
winner-less result. The code is 'all_candidates_failed'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
failures
|
dict
|
Mapping of candidate name to the |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
failures |
dict
|
Mapping of candidate name to its |
Source code in skforecast_ai/exceptions.py
353 354 355 356 357 358 359 360 361 | |
CandidateFailedWarning ¶
Bases: UserWarning
Warned by compare() when an individual candidate fails.
The comparison continues with the remaining candidates; the failure
is recorded in the 'error' column of the results table and a
CandidateFailure is kept in ComparisonResult.failures.
DataSentToLLMWarning ¶
Bases: UserWarning
Warned when data values are sent to the LLM against send_data_to_llm.
ask(context=...) always sends the predicted values a result carries,
because a question about a result cannot be answered from summary
statistics alone. That override is silent otherwise, so a user who set
send_data_to_llm=False for privacy reasons would still ship values
off the machine without being told. A result that carries no such
values (for example a CodeGenerationResult) does not trigger it.
The input data is not sent: the observed values that the predictions
of a backtest carry (y_true) are left out of the context unless
send_data_to_llm is True, and a result holds no other value of the
data it was fitted on.
FoldsLeftOutWarning ¶
Bases: UserWarning
Warned by backtest() and compare() when the backtest of several
series did not forecast a series in some test folds where it has
values to evaluate.
ForecasterRecursiveMultiSeries and a ForecasterFoundation model
leave a series out of a fold they cannot forecast (one that starts
late, say) without a warning of skforecast. The folds that forecast
each series are read from the level and fold of the predictions:
the metrics of a series left out of some folds, and the average across
series, are computed on fewer folds than those of the others. The
warning names the series (in compare(), the candidates) with those
folds, as the explanation does. A series that no fold forecasts raises
before running instead.
IntervalCoverageWarning ¶
Bases: UserWarning
Warned by backtest() and compare() when the prediction interval
covers clearly less than its nominal level.
The backtesting of skforecast measures the share of the actual values
that fall inside the interval (coverage in the metrics). The warning
is emitted when, in any series, that share is below the nominal coverage
(upper - lower of interval) by more than two binomial standard
errors for the number of predictions, and by at least 5 percentage
points. It names the series (or, in compare(), the candidates) and
their coverage: such an interval must not be read at its nominal level.
MissingBackendWarning ¶
Bases: UserWarning
Warned when a model needs a package that is not installed: by
compare() when it leaves a candidate out, and by plan() when the
estimator of the plan is one of them.
compare() without candidates includes ForecasterFoundation, whose
default model needs a backend package (for Chronos-2,
chronos-forecasting) that skforecast-ai does not install by default,
and, with several series, XGBRegressor, whose package no extra of
skforecast-ai installs. When that package is missing, the candidate is
dropped instead of failing on every call, and this warning says which
package to install. The comparison explanation records it as well.
plan() still makes a plan whose estimator is not installed (XGBoost,
CatBoost), since its script may run on another machine, and warns that
running it here fails.
PlanEditsDiscardedWarning ¶
Bases: UserWarning
Warned by refine_plan() when edits made to the plan are discarded.
refine_plan() builds the refined plan with plan(), from the
decisions it carries over (the overrides of RefinePlanOverrides and
the fields in ForecastPlan.overridden_fields). A value changed by
hand in the plan (in forecaster_kwargs, the metric, the
preprocessing steps...) that plan() would not build is therefore
lost. The warning names those fields; its text is also kept in the
warnings of the refined plan.
It is warned too when the refined plan leaves out decisions of the plan
that its forecaster or its estimator cannot take: the estimator_kwargs
written for another estimator, or the differentiation, the calendar
features, the target transformer, the lags refined by the LLM and the
transformer_exog and categorical_features of an autoregressive plan
switched to ForecasterStats, ForecasterFoundation or the baseline.
The warning names each value and whether the user, the LLM or the rules
chose it. Edits by hand and decisions left out are named in a single
warning.
compare() without candidates warns it too when the plan of its
CVResult runs as the row 'Strategy plan', which plan() rebuilds
in the same way: the edits it would not build do not run.
UnrecommendedForecasterWarning ¶
Bases: UserWarning
Warned by plan() when the requested forecaster is not recommended.
The forecaster is supported and is used as requested, but it was left
out of ForecastingProfile.forecaster_candidates for this dataset,
typically because it is expected to be very slow or to perform poorly
(for example, Auto-ARIMA on high-frequency data).
skforecast_ai.schemas.errors.ErrorInfo ¶
Bases: BaseModel
Plain-data description of an error, for a reader outside Python.
Built with ErrorInfo.from_exception(). It never holds a traceback or
generated code: only a stable code, the message, the argument at fault
and an optional remedy.
Attributes:
| Name | Type | Description |
|---|---|---|
code |
str
|
One of |
message |
str
|
Error message. For an internal error, the exception type and the first line of its message, at most 200 characters. |
field |
(str, None)
|
Name of the argument (or the field of a plan, profile or CV) at fault, when the error is tied to one. |
hint |
(str, None)
|
Optional remedy. |
Methods:
| Name | Description |
|---|---|
from_exception |
Describe an exception raised by a skforecast-ai call. |
Attributes¶
model_config
class-attribute
instance-attribute
¶
model_config = ConfigDict(frozen=True, extra='forbid')
Methods:¶
from_exception
classmethod
¶
from_exception(exc)
Describe an exception raised by a skforecast-ai call.
- A
SkforecastAIErrorkeeps its code, message, field and hint. The message of anAllCandidatesFailedErrorleaves out how to inspectexc.failures, which only exists in Python. - A pydantic
ValidationError(a plan or a profile that does not validate) is'invalid_argument'. When the validator raised aSkforecastAIError, its code, message and hint are used. The field is the location of the first error, or the field of that error when the location is empty (a check on the whole model). When there are several errors, the message says how many are not shown. - Any other exception is
'internal_error', described by its type and the first line of its message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc
|
Exception
|
Exception to describe. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
info |
ErrorInfo
|
Plain-data description of |
Source code in skforecast_ai/schemas/errors.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |