Skip to content
Increment 0.1.0a6 prerelease documentation. These docs describe the increment 0.1.0a6 prerelease (v0.1.0a6). Its API may change. Install: pip install 'increment==0.1.0a6' Keep any extras requested by the guide, such as increment[dashboard]==0.1.0a6.

Errors

IdentificationGate

Overlap/positivity policy for an observational comparison.

Defaults refuse rather than silently proceed when propensities are extreme (overlap="trim" opts in to dropping poor overlap instead). min_propensity bounds a symmetric band: a fitted propensity outside [min_propensity, 1 - min_propensity] trips.

IdentificationError(message, code, context)

Identification gate refused: the data cannot support the requested estimand.

Every call site names its own stable dotted code and carries structured context; there is no generic default.

CapabilityError

Raised when a source cannot honestly provide a requested capability.

Typed errors and refusal specifications describe invalid definitions, unsupported requests, and wire-format failures.

An arm-lift readout with no observed treatment arm raises InvalidRequestError with code readout.arms.no_treatment. Its context identifies control_group and observed_arms; supply at least one non-control arm to estimate a contrast. This does not prevent reading arm-level counts or running an otherwise defined allocation diagnostic.

Heterogeneity estimation checks its identification contract before reading outcomes. InvalidRequestError codes and their context:

  • cate.identification.randomized_only (caller, mechanism): estimate_cate needs a randomized source.
  • cate.identification.unsupported_mechanism (caller, mechanism, supported): the design is neither randomized nor observational.
  • cate.identification.unsupported_missing_policy (caller, missing): an observational design must declare missing="refuse" for this path.
  • cate.identification.unsupported_max_smd (caller, max_smd): the observational max_smd balance gate is not implemented for this path.
CodedError(message, code, context)

A public error carrying a stable code and immutable call context.

CodedModel and unwrap_coded are public from increment.errors, not the root increment namespace.

CodedModel and every public input model that inherits it surface known field-validation failures from direct construction and direct model_validate, model_validate_json, and model_validate_strings calls as InvalidRequestError refusals with stable model.field.* codes and structured context. Definition-specific validators raise DefinitionError; shared finite-sample metric-type and CUPED refusals raise InvalidRequestError with the same conversion_inference.finite_sample.* code and structured context as frame, estimation and planning requests. Catch CodedError when handling both kinds by code. Pydantic schema boundaries such as TypeAdapter and an ordinary BaseModel containing one of these models still raise ValidationError: Pydantic captures the refusal because CodedError intentionally remains compatible with ValueError. Recover the coded refusal explicitly at those boundaries:

Only CodedModel (including Definitions) also translates declared-field Field constraint failures: they raise InvalidRequestError (a ValueError), with a model.field.* code, rather than pydantic.ValidationError. Code that catches validation failures from these models must catch (pydantic.ValidationError, increment.errors.InvalidRequestError) (or ValueError) rather than replacing one with the other. Uncoded-validator, root-level, and nested non-coded-model failures are reported as definition.validation with field locations when loading YAML definitions.

from pydantic import TypeAdapter, ValidationError
from increment.estimators import DefinitionError
import increment
from increment.errors import unwrap_coded
try:
TypeAdapter(increment.Definitions).validate_python({"day_boundary": "EST"})
except ValidationError as exc:
try:
unwrap_coded(exc)
except DefinitionError as coded:
refusal = {"code": coded.code, "context": dict(coded.context)}
else:
raise
CodedModel(data)

Mixin that translates attributable pydantic field failures to coded errors.

Direct construction and model_validate* calls surface InvalidRequestError for known field failures, while cross-field validators and unknown pydantic failure kinds remain ValidationError.

DefinitionError(message, code, context)

A definition YAML parse, model validation, or reference failed.

Carries message, the file or directory path given to the loader, and a copied sources mapping for duplicate-name errors.

InvalidRequestError

Raised when a public request is invalid.

RefusalSpec(code, error_type, render, template, keys)

Stable code, exception type, and renderer for one refusal.

Exactly one of render (a callable, for text that needs computation) or template (a str.format string, for plain interpolation) must be set. keys is the template’s own {placeholder} names, unioned with any explicitly declared extras; a render-only spec’s keys stays empty — its own call signature is its drift guard.

RETIRED_CODES

Lookup only: maps a retired refusal code to its canonical replacement, to a tuple of replacements when one code was split into several, or to None if the code was deleted with no replacement (a genuinely dead registration). Every retired/merged/deleted code in this codebase gets exactly one entry here in the same change that removes it from the live registry. A CodedError instance’s own .code never changes after construction — this map is for callers who catch an old code and need to migrate, and for tests/test_retired_codes.py’s enforcement.

UnsupportedRequestError

Raised when a recognized request is not supported.

WireFormatError

Raised when serialized source data has an invalid wire format.

unwrap_coded(exc)

Re-raise the first coded refusal buried in a pydantic ValidationError.

Use this at schema boundaries such as TypeAdapter or an ordinary BaseModel containing a CodedModel. Returns (does nothing) if no coded error is found, so the caller can re-raise the original ValidationError unchanged.

The raised refusal is a copy of the one exc holds, carrying the validator’s traceback and notes; every error exc holds is then left without a traceback or chained exception. exc keeps those errors out of reach of Python’s cycle collector, so any link from them back to the raised refusal would keep every caller’s variables in memory for the life of the process.

Library advisories are instances of IncrementWarning (or IncrementRuntimeWarning/IncrementDeprecationWarning, which also satisfy filterwarnings/pytest.warns matched against RuntimeWarning/ DeprecationWarning), carrying a stable .code and immutable .context alongside the free-text message — the warning counterpart to CodedError. Warnings with a declared deduplication scope also carry an immutable .dedupe_key. Randomized lift-cell readouts suppress repeated emissions with the same key while replaying captured estimator warnings within one operation; warnings without a key are not suppressed by that replay path.

Data-quality warnings from dataframe sources respect the current Python warning filter on every run, even when intermediate calculations are cached. Each cached calculation emits its warnings at most once per run, whether the run reads live data or takes a snapshot.

Filter and assert on .code rather than message text:

import warnings
from increment.estimators import IncrementWarning
with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
... # a call that may emit a library advisory
codes = {w.message.code for w in caught if isinstance(w.message, IncrementWarning)}
IncrementWarning(message, code, context, dedupe_key)

A public warning carrying a stable code, immutable context, and optional key.

Mirrors CodedError: .code is fixed at construction and .context is an immutable snapshot. A category that must also match RuntimeWarning/DeprecationWarning for existing filterwarnings calls should multiply-inherit from this class and that category (see IncrementRuntimeWarning, IncrementDeprecationWarning) rather than replacing it.

IncrementRuntimeWarning

A coded warning that also satisfies filterwarnings(category=RuntimeWarning).

IncrementDeprecationWarning

A coded warning that also satisfies filterwarnings(category=DeprecationWarning).

UnverifiedWarehouseWarning

A one-time notice that a connection’s warehouse is not one Increment verifies.