Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Most automated data-cleaning libraries fail in production for three reasons:

`freshdata` separates **planning** from **execution**:
* **`fd.suggest_plan(lf)`** runs a single streaming aggregation pass over a Polars `LazyFrame` (or pandas `DataFrame`), protects ID and target columns automatically, and outputs an inspectable, diffable `CleanPlan` containing precomputed scalar thresholds.
* **`fd.apply_plan(lf, plan)`** compiles those approved actions into pure, fused Polars expressions (`pl.Expr`)—requiring **zero `.collect()` calls** and **zero Python UDFs**. A `LazyFrame` in stays a `LazyFrame` out.
* **`fd.apply_plan(lf, plan)`** compiles those approved actions into pure, fused Polars expressions (`pl.Expr`)—requiring **zero Python UDFs**. A `LazyFrame` in stays a `LazyFrame` out, and a Polars-made plan needs **zero `.collect()` calls**. (A pandas-made plan with `parse_currency` runs one query over that column, see [Known differences](#known-differences-between-pandas-and-polars).)

---

Expand Down Expand Up @@ -169,6 +169,7 @@ The two backends give different results in these cases. `tests/test_known_differ
| Row order after `drop_duplicates` | Keeps the first row of each group, in order | No fixed order (`unique(maintain_order=False)`) |
| Replaying a plan on new data | Uses the fill value stored in the plan | Computes the fill value again on the new data |
| `CleanReport` for a LazyFrame | Not applicable | `original_rows` and `cleaned_rows` are `0`, because freshdata does not run a query to count rows |
| A pandas-made plan with `parse_currency`, applied to a LazyFrame | Not applicable | `apply_plan` runs one query (`collect()`) to check that each value is a currency string. If one is not, it skips the column. A Polars-made plan has no `parse_currency` step, so it stays fully lazy |

If you need the same result on both backends, use the same backend for planning and applying, and check the plan before you apply it.

Expand Down
20 changes: 20 additions & 0 deletions tests/test_known_differences.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,23 @@ def test_row_order_after_drop_duplicates():
assert fd.apply_plan(pd.DataFrame(data), fd.suggest_plan(pd.DataFrame(data), cfg), cfg)["k"].tolist() == [3, 1, 2]
lf = pl.LazyFrame(data)
assert "UNIQUE[maintain_order: false" in fd.apply_plan(lf, fd.suggest_plan(lf, cfg), cfg).explain()


def _count_collects(monkeypatch, lf, plan):
calls = []
real = pl.LazyFrame.collect
monkeypatch.setattr(pl.LazyFrame, "collect", lambda self, *a, **k: calls.append(1) or real(self, *a, **k))
out = fd.apply_plan(lf, plan)
assert isinstance(out, pl.LazyFrame)
return len(calls)


def test_pandas_plan_with_currency_runs_one_query_on_a_lazyframe(monkeypatch):
assert "pandas-made plan" in SECTION
assert "Polars-made plan" in README.split("---", 1)[0]
data = {"price": ["$10.00", "$20.00", "$30.00"]}
pandas_plan = fd.suggest_plan(pd.DataFrame(data))
polars_plan = fd.suggest_plan(pl.DataFrame(data))
assert "parse_currency" in [a.action for a in pandas_plan.actions]
assert _count_collects(monkeypatch, pl.LazyFrame(data), pandas_plan) == 1
assert _count_collects(monkeypatch, pl.LazyFrame(data), polars_plan) == 0
Loading