From 04fffb17010d229d09da94bac497d96306b5870c Mon Sep 17 00:00:00 2001 From: Johnny Wilson Dougherty Date: Tue, 1 Dec 2026 15:51:13 +0530 Subject: [PATCH] docs: scope the zero-collect claim to Polars-made plans PR #538 made apply_plan run one query on a LazyFrame when a pandas-made plan has parse_currency. The README still said apply_plan needs zero collect() calls for every plan. Scope the claim and add a Known differences row. A test counts collect() calls for both plan kinds. --- README.md | 3 ++- tests/test_known_differences.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 70180f8..d3e6438 100644 --- a/README.md +++ b/README.md @@ -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).) --- @@ -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. diff --git a/tests/test_known_differences.py b/tests/test_known_differences.py index 15d5b44..e325f9f 100644 --- a/tests/test_known_differences.py +++ b/tests/test_known_differences.py @@ -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