compileml.export

export_sql

def export_sql(artifact: dict, *, table: str = 'features', dialect: str = 'ansi', explain: bool = False, top_k: int | None = None) -> str

from compileml.export import export_sql

Render the artifact as one SQL query over table.

table must expose one float64 column per feature, named exactly as in features.names (imputation per the artifact's missing policy is the loader's job — SQL NULL comparisons would otherwise silently skip branches). Returns all source columns plus raw_micro, latent_micro, latent_int, band, and pd_ppm.

Dialects: "ansi" (GREATEST/LEAST) or "sqlite" (two-arg MAX/MIN).

With explain=True each row also carries the top top_k adverse and favorable reasons as reason_neg_<s>_code / reason_neg_<s>_impact and reason_pos_<s>_code / reason_pos_<s>_impact (NULL where a slot is empty) — the codes and display-scale integer impacts decide(..., explain=True) returns, in order. Working columns used to compute them are prefixed cml_. top_k defaults to the artifact's own.

Raises: ExportError: EXPLAIN_NOT_EXACT when attribution is not exact.

Parameters#

NameTypeDefaultKind
artifactdictrequiredpositional
tablestr'features'keyword-only
dialectstr'ansi'keyword-only
explainboolFalsekeyword-only
top_kint | NoneNonekeyword-only

Returns#

str

Raises#

  • ValueError

Read from the function body and the private helpers it calls, not inferred. A function that raises nothing has no section here.

Example#

python
from compileml.export import export_sql
 
sql = export_sql(artifact, table="applications")

Worked example: export_sql →