imputers#
Registered curation steps that fill missing canonical values.
Functions#
|
Fill missing values in numeric columns, then cast to dtype. |
|
Fill missing |
Impute each row's output from a grouped statistic of another column. |
Module Contents#
- openplaces.io.curator.imputers.fill_missing_numeric(state: openplaces.io.curator.CurateState, columns: list[str], fill_value: float = 0, dtype: str = 'int64') openplaces.io.curator.CurateState#
Fill missing values in numeric columns, then cast to dtype.
For an evidence-derived column where a missing value carries different meaning than a confirmed value of fill_value (e.g. “no Overture address point matched this footprint at all” vs. “an Overture point matched and reported 0 dwellings”), place this step after anything that should see the true missing value (a priority reconciliation, a vote) — from that point on it only reshapes the column for output.
- Parameters:
columns (list of str) – Columns to fill and cast. Missing columns are skipped.
fill_value (float, optional) – Value used to fill missing entries (default 0).
dtype (str, optional) – Target dtype after filling (default
'int64').
- openplaces.io.curator.imputers.impute_n_dwellings(state: openplaces.io.curator.CurateState) openplaces.io.curator.CurateState#
Fill missing
n_dwellingsfrom an occupancy-class lookup.Rows still missing a dwelling-unit count after value reconciliation are filled from the occupancy class of the first available
purpose_subgroup/occupancy_typecolumn, using the occupancy-to-units mapping from Lochhead et al. (2026, Table 3).
- openplaces.io.curator.imputers.impute_from_group_statistic(state: openplaces.io.curator.CurateState, group_column: str, value_column: str, output: str, statistic: str = 'mode', overrides: str | None = None) openplaces.io.curator.CurateState#
Impute each row’s output from a grouped statistic of another column.
For every row, output is set to a statistic of value_column computed across all rows sharing the same group_column value (its cohort). The default statistic is the mode (most common value), which learns a group -> value mapping by majority vote; mean, median, min, and max are also supported for numeric columns.
An optional overrides crosswalk corrects known-bad group mappings: a two-column lookup (group value -> corrected output) loaded by recipe id. Corrections win wherever the row’s group is a key in the table — even when the correction itself is blank (explicit null), which suppresses the learned statistic for that group rather than falling back to it. Matching is exact after trimming surrounding whitespace only (no case-folding or punctuation normalization), so override CSV keys must match the group column’s real values. The grouped statistic fills every other group.
Generic over any pair of columns: holds no references to specific entities or sources, so it can be reused for any cross-linked categorical columns.
- Parameters:
group_column (str) – Column whose value defines each row’s cohort.
value_column (str) – Column the statistic is computed over within each cohort.
output (str) – Name of the column to write.
statistic (str, optional) – Cohort statistic: mode (default), mean, median, min, or max.
overrides (str, optional) – Recipe id of a two-column correction crosswalk (group value -> corrected output). Corrections take precedence over the computed statistic.