preprocessing.checking.check_interval

preprocessing.checking.check_interval(
    interval=None,
    ensure_symmetric_intervals=False,
    quantiles=None,
    alpha=None,
    alpha_literal='alpha',
)

Validate that a confidence interval specification is valid.

This function checks that interval values are properly formatted and within valid ranges for confidence interval prediction.

Parameters

Name Type Description Default
interval Union[List[float], Tuple[float], None] Confidence interval percentiles (0-100 inclusive). Should be [lower_bound, upper_bound]. Example: [2.5, 97.5] for 95% interval. None
ensure_symmetric_intervals bool If True, ensure intervals are symmetric (lower + upper = 100). False
quantiles Union[List[float], Tuple[float], None] Sequence of quantiles (0-1 inclusive). Currently not validated, reserved for future use. None
alpha Optional[float] Confidence level (1-alpha). Currently not validated, reserved for future use. None
alpha_literal Optional[str] Name used in error messages for alpha parameter. 'alpha'

Raises

Name Type Description
TypeError If interval is not a list or tuple.
ValueError If interval doesn’t have exactly 2 values, values out of range (0-100), lower >= upper, or intervals not symmetric when required.

Examples

from spotforecast2_safe.preprocessing.checking import check_interval

# Valid 95% confidence interval — no error
check_interval(interval=[2.5, 97.5])

# Valid symmetric interval — no error
check_interval(interval=[2.5, 97.5], ensure_symmetric_intervals=True)

# Invalid: not symmetric
try:
    check_interval(interval=[5, 90], ensure_symmetric_intervals=True)
except ValueError as e:
    print(f"ValueError (not symmetric): {e}")

# Invalid: wrong number of values
try:
    check_interval(interval=[2.5, 50, 97.5])
except ValueError as e:
    print(f"ValueError (wrong length): {e}")

# Invalid: out of range
try:
    check_interval(interval=[-5, 105])
except ValueError as e:
    print(f"ValueError (out of range): {e}")

print("check_interval examples done.")
ValueError (not symmetric): Interval must be symmetric, the sum of the lower, (5), and upper, (90), interval bounds must be equal to 100. Got 95.
ValueError (wrong length): `interval` must contain exactly 2 values, respectively the lower and upper interval bounds. For example, interval of 95% should be as `interval = [2.5, 97.5]`.
ValueError (out of range): Lower interval bound (-5) must be >= 0 and < 100.
check_interval examples done.