Skip to content

refactor(core): Unify ActionRecord, CleanPlan, and CleanReport schemas across _core and polars_engine #531

Open

Description

@JohnnyWilson16

Summary

Currently, freshdata maintains two divergent definitions for the core repair plan data models:

  1. src/freshdata/_core/models.py:
    • ActionRecord(stage, column, action, parameters, rows_affected, rationale)
    • CleanPlan(actions: tuple[ActionRecord, ...])
    • CleanReport(original_rows, cleaned_rows, original_cols, cleaned_cols, actions)
  2. src/freshdata/polars_engine.py:
    • ActionRecord(column, stage, operation, params, affected_rows, rationale)
    • CleanPlan(rename_map, actions, drop_duplicates, total_rows)
    • CleanReport(plan, renamed_columns, dropped_columns, total_actions)

Motivation & Impact

  • Agent Experience (AX): Autonomous AI coding assistants and LLM agents that generate or inspect dry-run plans fail with AttributeError depending on which module they import (.action vs .operation, .parameters vs .params, .rows_affected vs .affected_rows).
  • Developer Experience (DX): Dual definitions introduce maintenance fragmentation. Features added to _core do not automatically propagate to polars_engine.py.
  • User Experience (UX): Calling diff() on plans constructed across modules fails due to incompatible internal key mappings.

Proposed Solution

  1. Consolidate into a single canonical source of truth in src/freshdata/_core/models.py.
  2. Standardize ActionRecord:
    • Primary fields: stage: str, column: str, action: str, params: dict[str, Any], rows_affected: int, rationale: str.
    • Provide backwards-compatible properties: operation -> action, parameters -> params, affected_rows -> rows_affected.
  3. Standardize CleanPlan:
    • Include rename_map: Mapping[str, str] = field(default_factory=dict) and drop_duplicates: bool = False, total_rows: int = 0.
    • Update CleanPlan.diff() to handle both structural and parameter diffs cleanly.
  4. Update src/freshdata/polars_engine.py to import and re-export the unified models from freshdata._core.models instead of declaring duplicates.

Acceptance Criteria

  • All 43 existing unit and property tests in tests/ pass without regression.
  • Both _core and polars_engine code paths consume the unified dataclasses.
  • Serialization (to_dict()) produces consistent, JSON-roundtrip-safe structures.
  • Branch coverage remains >= 90%.

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

Activity

  1. added
    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

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions