pdstools.adm.HealthCheckImport¶
Attributes¶
Classes¶
Structured reader options for one Health Check input source. |
|
Simple row predicate applied during Health Check source normalization. |
|
Declarative repairs applied to one input before pdstools validation. |
|
Read and normalization options for one Health Check source. |
|
Non-content metadata describing an imported source. |
|
Imported objects and constructor-ready normalized source data. |
Functions¶
|
Apply safe, declarative repairs to one Health Check input. |
|
Return column names read from a Health Check source. |
|
Import model, optional predictor, and optional prediction data. |
|
Resolve the |
|
Atomically persist canonical Health Check cache parquet files. |
Module Contents¶
- HealthCheckSource¶
- ConfiguredDtype¶
- logger¶
- MODEL_CACHE_FILENAME = 'PR_DATA_DM_ADMMART_MDL_FACT.parquet'¶
- PREDICTOR_CACHE_FILENAME = 'PR_DATA_DM_ADMMART_PRED.parquet'¶
- PREDICTION_CACHE_FILENAME = 'PR_DATA_DM_SNAPSHOTS.parquet'¶
- class HealthCheckReadOptions¶
Structured reader options for one Health Check input source.
- Parameters:
delimiter (str, optional) – Field delimiter for CSV, TSV, or TXT input.
quote_char (str, optional) – Quote character for CSV, TSV, or TXT input. Set to None to disable quote handling.
encoding (str, default "utf8") – Text encoding forwarded to Polars.
has_header (bool, default True) – Whether the first input row contains column names.
skip_rows (int, default 0) – Number of rows to skip before reading delimited text.
infer_schema_length (int, optional) – Number of rows used for schema inference. Use zero to read all columns as strings before applying normalization overrides.
ignore_errors (bool, default False) – Continue parsing rows that contain values incompatible with the inferred delimited-text schema.
null_values (tuple[str, ...], optional) – Values interpreted as null for delimited text.
schema_overrides (Mapping[str, ConfiguredDtype]) – Reader-level column type overrides.
excel_sheet_name (str, optional) – Excel sheet name to read.
excel_sheet_id (int, optional) – One-based Excel sheet index to read.
excel_header_row (int, optional) – Zero-based Excel row containing column names.
- schema_overrides: collections.abc.Mapping[str, ConfiguredDtype]¶
- class HealthCheckRowFilter¶
Simple row predicate applied during Health Check source normalization.
- Parameters:
column (str) – Column to evaluate, matched case-insensitively.
operator (str) – Predicate operator. Supported values are
==,!=,contains,not_contains,starts_with,not_starts_with,ends_with,not_ends_with,is_null, andis_not_null.value (str, optional) – Predicate value. Required for all operators except
is_nullandis_not_null.
- operator: Literal['==', '!=', 'contains', 'not_contains', 'starts_with', 'not_starts_with', 'ends_with', 'not_ends_with', 'is_null', 'is_not_null']¶
- class SourceNormalizationOptions¶
Declarative repairs applied to one input before pdstools validation.
- Parameters:
rename_columns (Mapping[str, str]) – Existing columns to rename, matched case-insensitively.
row_filters (tuple[HealthCheckRowFilter, ...]) – Simple row predicates to apply before column cleanup.
text_replacements (Mapping[str, Mapping[str, str]]) – Literal text replacements by column, matched case-insensitively.
fill_null_values (Mapping[str, object]) – Existing columns whose null values should be filled with a constant, matched case-insensitively.
derived_columns (Mapping[str, str]) – Columns to create or replace from a source column (
target=source) or numeric subtraction (target=left-right), matched case-insensitively. String concatenation is supported astarget=concat(column, "literal", other).drop_columns (tuple[str, ...]) – Existing columns to remove, matched case-insensitively.
type_overrides (Mapping[str, ConfiguredDtype]) – Non-strict casts to apply, matched case-insensitively.
timestamp_column (str, optional) – Existing timestamp column to parse, or a new column to create when a fallback is configured.
timestamp_format (str, optional) – Explicit
strptimeformat for a string timestamp column.timestamp_fallback (datetime or date, optional) – Value used for missing or unparseable timestamps.
constant_columns (Mapping[str, object]) – New columns and their constant values.
- rename_columns: collections.abc.Mapping[str, str]¶
- row_filters: tuple[HealthCheckRowFilter, Ellipsis] = ()¶
- text_replacements: collections.abc.Mapping[str, collections.abc.Mapping[str, str]]¶
- fill_null_values: collections.abc.Mapping[str, object]¶
- derived_columns: collections.abc.Mapping[str, str]¶
- type_overrides: collections.abc.Mapping[str, ConfiguredDtype]¶
- timestamp_fallback: datetime.datetime | datetime.date | None = None¶
- constant_columns: collections.abc.Mapping[str, object]¶
- class SourceImportOptions¶
Read and normalization options for one Health Check source.
- read: HealthCheckReadOptions¶
- normalize: SourceNormalizationOptions¶
- class HealthCheckSourceMetadata¶
Non-content metadata describing an imported source.
- class HealthCheckImportResult¶
Imported objects and constructor-ready normalized source data.
- datamart: pdstools.adm.ADMDatamart.ADMDatamart¶
- prediction: pdstools.prediction.Prediction.Prediction | None¶
- model_data: polars.LazyFrame¶
- sources: collections.abc.Mapping[str, HealthCheckSourceMetadata]¶
- normalize_health_check_data(df: polars.LazyFrame, options: SourceNormalizationOptions | None = None) tuple[polars.LazyFrame, tuple[str, Ellipsis]]¶
Apply safe, declarative repairs to one Health Check input.
- Parameters:
df (pl.LazyFrame) – Raw input data.
options (SourceNormalizationOptions, optional) – Repairs to apply. Column names are matched case-insensitively.
- Returns:
Normalized data and data-safe descriptions of applied repairs.
- Return type:
- Raises:
ValueError – If configured columns do not exist, settings conflict, or a configured data type is unsupported.
- preview_health_check_columns(source: HealthCheckSource, options: HealthCheckReadOptions | None = None) tuple[str, Ellipsis]¶
Return column names read from a Health Check source.
- Parameters:
source (str, path-like, or BytesIO) – Input source to inspect.
options (HealthCheckReadOptions, optional) – Reader options to apply while inspecting the source.
- Returns:
Column names found in the source.
- Return type:
- import_health_check_data(model_source: HealthCheckSource, predictor_source: HealthCheckSource | None = None, prediction_source: HealthCheckSource | None = None, *, model_options: SourceImportOptions | None = None, predictor_options: SourceImportOptions | None = None, prediction_options: SourceImportOptions | None = None, extract_pyname_keys: bool = True, predictor_categorization: collections.abc.Mapping[str, str | list[str]] | None = None, predictor_categorization_uses_regex: bool = False) HealthCheckImportResult¶
Import model, optional predictor, and optional prediction data.
The returned source frames are normalized but remain constructor-ready. This allows canonical parquet files to be loaded later by the normal
ADMDatamartandPredictionvalidation paths.- Parameters:
model_source (HealthCheckSource) – Required model snapshot input.
predictor_source (HealthCheckSource, optional) – Predictor-binning snapshot input.
prediction_source (HealthCheckSource, optional) – Prediction snapshot input.
model_options (SourceImportOptions, optional) – Independent read and normalization options for each source.
predictor_options (SourceImportOptions, optional) – Independent read and normalization options for each source.
prediction_options (SourceImportOptions, optional) – Independent read and normalization options for each source.
extract_pyname_keys (bool, default True) – Whether to extract context keys embedded in the model Name field.
predictor_categorization (Mapping[str, str or list[str]], optional) – Category names mapped to PredictorName substring patterns.
predictor_categorization_uses_regex (bool, default False) – Interpret predictor categorization patterns as regular expressions.
- Returns:
Validated analysis objects, constructor-ready source data, metadata, and data-safe descriptions of applied repairs.
- Return type:
- resolve_health_check_output_dir(model_source: HealthCheckSource | None = None, predictor_source: HealthCheckSource | None = None, prediction_source: HealthCheckSource | None = None, *, output_parent: str | os.PathLike[str] | None = None) pathlib.Path¶
Resolve the
HCoutput directory for processed parquet files.An explicit output parent takes precedence. Otherwise, the first filesystem source is selected in model, predictor, prediction order. In-memory-only imports fall back to the current working directory.
- Parameters:
model_source (HealthCheckSource, optional) – Input sources used to select a filesystem parent.
predictor_source (HealthCheckSource, optional) – Input sources used to select a filesystem parent.
prediction_source (HealthCheckSource, optional) – Input sources used to select a filesystem parent.
output_parent (str or path-like, optional) – Explicit directory under which the
HCdirectory is created.
- Returns:
Resolved output directory ending in
HC.- Return type:
- save_health_check_parquet(result: HealthCheckImportResult, output_parent: str | os.PathLike[str]) dict[str, pathlib.Path]¶
Atomically persist canonical Health Check cache parquet files.
All requested frames are written to temporary files before any canonical file is replaced. Optional canonical files from an earlier import are removed after a successful write when the corresponding source is absent.
- Parameters:
result (HealthCheckImportResult) – Imported source frames and validated analysis objects.
output_parent (str or path-like) – Parent directory under which an
HCdirectory is created.
- Returns:
Canonical paths keyed by
model,predictor, andprediction.- Return type: