Skip to content

fix(core): Track column name identity mapping deterministically across CleanPlan stages #534

Open

Description

@JohnnyWilson16

Summary

In src/freshdata/_core/stages.py, stage_column_names normalizes column names (e.g. " First Name " -> "first_name").
Subsequent stages (stage_missing, stage_outliers) produce ActionRecord instances keyed to the normalized column names.

In src/freshdata/_core/backends.py:60-75:

renames = {}
for a in plan.actions:
    if a.stage == "column_names" and a.action == "normalize_name":
        renames[a.column] = a.parameters["to"]
if renames:
    out = out.rename(columns=renames)

for a in plan.actions:
    # ...
    col = renames.get(a.column, a.column)
    if col not in out.columns:
        continue

The Problem

  1. If an external user, custom script, or autonomous agent constructs a CleanPlan where an action specifies the original column name (e.g. " First Name "), renames.get resolves it to "first_name".
  2. However, if the action was generated by suggest_plan, a.column is already "first_name". renames.get("first_name", "first_name") resolves to "first_name".
  3. If columns have overlapping or cyclic rename mappings, or if stages are executed selectively without column_names, column resolution becomes non-deterministic and can silently skip actions (if col not in out.columns: continue).

Proposed Solution

  1. Explicitly store rename_map as a top-level field on CleanPlan (as already implemented in polars_engine.CleanPlan).
  2. Provide a deterministic plan.resolve_column(col_name) helper method that maps either original or normalized names to the current active DataFrame column name.
  3. Emit a warning or raise a descriptive KeyError instead of silently continuing when an action's target column cannot be resolved in out.columns.

Acceptance Criteria

  • Custom plans targeting both original and normalized column names execute reliably.
  • Actions targeting non-existent columns are not silently ignored without warning or reporting.
  • Backwards compatibility is preserved for existing CleanPlan instances.

👋 Want to work on this issue?
Comment /assign below to claim it! Check out the First Contribution Guide for setup instructions.

Activity

  1. added
    bug
    enhancement
    help wanted
    on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugenhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions