Skip to content

tdfs4ds.feature_props

tdfs4ds.feature_props

Feature properties (0.3.7.23): what is true of a feature's data for any use.

A valid range (or allowed values), the meaning of a NULL and whether one is expected, sensitivity. Declared once with :func:upload_feature_properties, read with :func:feature_properties, shown everywhere with :func:render_properties_text, verified ON DEMAND with :func:check_feature_properties (sanity checks, the agent). Nothing is declared, checked or created unless asked: run() and roll_out() never read these objects.

Modules are named so as not to shadow the exported functions: declare, read, checks, render, store, state, valtypes.

__all__ module-attribute

__all__ = ['upload_feature_properties', 'feature_properties', 'properties_for_process', 'check_feature_properties', 'check_sql', 'render_properties_text']

upload_feature_properties

upload_feature_properties(source, *, allowed_values=None, data_domain: Optional[str] = None, author: Optional[str] = None, dry_run: bool = False) -> dict

Declare properties of registered features: a valid range, allowed values, the meaning of NULL and whether it is expected, sensitivity. One row per feature.

source: a DataFrame, a 'db.view' / 'db.table' name or SQL text with the columns FEATURE_NAME (required), ENTITY_NAME, DATA_DOMAIN (else data_domain / tdfs4ds.DATA_DOMAIN), PROCESS (a PROCESS_ID or process view: the declaration then holds for that process only), VALID_MIN, VALID_MAX, ALLOWED_VALUES (JSON array, |- or ,-delimited), NULLABLE (Y/N), NULL_MEANING (zero / not_applicable / unknown), SENSITIVE (Y/N), SENSITIVITY_REASON. A column absent from the source, or an empty cell, declares nothing for that property; a declaration REPLACES the feature's previous one (the valid-time history keeps it). allowed_values: a second source (FEATURE_NAME[, ENTITY_NAME, DATA_DOMAIN], ALLOWED_VALUE).

Types come from the catalog; bounds and allowed values must be valid literals of the feature's type. Unknown features, ambiguous names (several entities / domains) and invalid rows are reported and never written. dry_run=True returns the plan, creates and writes nothing. The tables are created by the first real declaration. Declared properties are never checked by run(): see check_feature_properties.

Returns {written, unchanged, unknown, ambiguous, invalid, statements, created, dry_run}.

feature_properties

feature_properties(features: Optional[Iterable[str]] = None, data_domains: Optional[Iterable[str]] = None, as_of=None) -> pd.DataFrame

The declared properties of features, one row per (feature, process) rule.

Columns: DATA_DOMAIN, ENTITY_NAME, FEATURE_NAME, PROCESS_ID, VALID_MIN, VALID_MAX, ALLOWED_VALUES (list or None), NULLABLE, NULL_MEANING, SENSITIVE (booleans or None), SENSITIVITY_REASON, AUTHOR, DB_USER, VALID_FROM. as_of reads the declarations as they were at that valid time (VALIDTIME AS OF on the base tables, primary store only). With read-only stores attached that offer the objects, the current read is their union, the first store winning (a FEATURE_STORE column). An empty frame, with NO statement, when nothing was ever declared in the store. Never raises on a read failure of an attached store.

properties_for_process

properties_for_process(props_df: DataFrame, process_row) -> pd.DataFrame

The rows of props_df that apply to one process (pure).

process_row: a mapping with PROCESS_ID and, optionally, DATA_DOMAIN / ENTITY_NAME / FEATURE_NAMES (comma list). A row with no PROCESS_ID applies to every producing process; a row for another process is dropped; for one feature, a row of this process wins over the general one.

check_feature_properties

check_feature_properties(features=None, data_domains=None, as_of=None, history: bool = False) -> pd.DataFrame

Count, per declared feature, the stored values that break its declared properties.

Columns: DATA_DOMAIN, ENTITY_NAME, FEATURE_NAME, PROCESS_ID, N_ROWS (stored values checked), N_OUT_OF_RANGE (outside VALID_MIN / VALID_MAX), N_NOT_ALLOWED (not in the allowed values), N_UNEXPECTED_NULL (NULL where NULLABLE = N), FIRST_VIOLATION (with history=True: the earliest ValidStart of a violating row, else None) and ERROR (the database message when a table could not be read; its counts are then None).

The values are read at the current valid time, at as_of, or over the WHOLE history (history=True, NONSEQUENCED VALIDTIME, which can be expensive). One aggregate statement per storage table. Read-only; never called by run() / roll_out(). No statement at all, and an empty frame, when nothing is declared in the store.

check_sql

check_sql(table: str, rules: List[dict], *, qualifier: str = 'CURRENT VALIDTIME', history: bool = False) -> str

One aggregate statement on one storage table (pure).

table: the qualified FS_T_* table. rules: dicts with feature_id, feature_type, vmin, vmax, allowed (list), nullable (False = NULL not expected) and optionally process_id. Columns per rule i: N_i rows, OOR_i out of range, NA_i not allowed, NL_i unexpected NULL and, with history, FV_i the earliest ValidStart of a violating row. qualifier: CURRENT VALIDTIME, VALIDTIME AS OF TIMESTAMP '...' or, with history, NONSEQUENCED VALIDTIME.

render_properties_text

render_properties_text(prop_row, lang: str = 'en') -> str

Fixed sentences for one row of feature_properties() (a mapping or a Series), joined by a space; '' when nothing is declared. lang: 'en' or 'fr'.

Submodules