|
11 | 11 | from .config import CleanConfig, merge_options |
12 | 12 | from .engine.context import build_contexts |
13 | 13 | from .engine.model_select import EngineMode, rank_missing_models |
14 | | -from .plan import suggest_plan |
| 14 | +from .plan import RepairPlan, build_repair_plan, suggest_plan |
15 | 15 | from .profile import Profile, build_profile |
16 | 16 | from .report import CleanReport |
17 | 17 |
|
@@ -132,6 +132,46 @@ def clean( |
132 | 132 | return from_pandas(result, df) |
133 | 133 |
|
134 | 134 |
|
| 135 | +def plan( |
| 136 | + df: pd.DataFrame, |
| 137 | + *, |
| 138 | + mode: str = "suggest", |
| 139 | + config: CleanConfig | None = None, |
| 140 | + **options: object, |
| 141 | +) -> RepairPlan: |
| 142 | + """Build a previewable, serializable repair plan without changing *df*. |
| 143 | +
|
| 144 | + ``mode="suggest"`` runs the configured cleaner and records the proposed |
| 145 | + row, column, and cell patches. ``mode="inspect"`` records only the source |
| 146 | + fingerprint and shape. ``mode="repair_safe"`` limits the plan to |
| 147 | + deterministic representation repairs by disabling statistical engine |
| 148 | + actions. |
| 149 | + """ |
| 150 | + return build_repair_plan(to_pandas(df), mode=mode, config=config, **options) |
| 151 | + |
| 152 | + |
| 153 | +def repair( |
| 154 | + df: pd.DataFrame, |
| 155 | + *, |
| 156 | + mode: str = "repair_safe", |
| 157 | + approved_patch_ids: set[str] | None = None, |
| 158 | + return_plan: bool = False, |
| 159 | + config: CleanConfig | None = None, |
| 160 | + **options: object, |
| 161 | +) -> pd.DataFrame | tuple[pd.DataFrame, RepairPlan]: |
| 162 | + """Apply a repair mode and optionally return the repair plan. |
| 163 | +
|
| 164 | + ``mode="repair_reviewed"`` applies only ``approved_patch_ids``. Other |
| 165 | + modes apply every patch proposed by the plan. |
| 166 | + """ |
| 167 | + repair_plan = build_repair_plan(to_pandas(df), mode=mode, config=config, **options) |
| 168 | + approved = set(approved_patch_ids or ()) if mode == "repair_reviewed" else None |
| 169 | + repaired = from_pandas(repair_plan.apply(approved), df) |
| 170 | + if return_plan: |
| 171 | + return repaired, repair_plan |
| 172 | + return repaired |
| 173 | + |
| 174 | + |
135 | 175 | def _engine_mode(cfg: CleanConfig) -> EngineMode: |
136 | 176 | mode = cfg.engine_mode or "balanced" |
137 | 177 | return "balanced" if mode == "balanced" else "aggressive" |
|
0 commit comments