Skip to content

Commit 9dcf0d4

Browse files
docs: scope the zero-collect claim to Polars-made plans (#549)
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.
1 parent 5bf57ce commit 9dcf0d4

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Most automated data-cleaning libraries fail in production for three reasons:
1414

1515
`freshdata` separates **planning** from **execution**:
1616
* **`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.
17-
* **`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.
17+
* **`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).)
1818

1919
---
2020

@@ -169,6 +169,7 @@ The two backends give different results in these cases. `tests/test_known_differ
169169
| Row order after `drop_duplicates` | Keeps the first row of each group, in order | No fixed order (`unique(maintain_order=False)`) |
170170
| Replaying a plan on new data | Uses the fill value stored in the plan | Computes the fill value again on the new data |
171171
| `CleanReport` for a LazyFrame | Not applicable | `original_rows` and `cleaned_rows` are `0`, because freshdata does not run a query to count rows |
172+
| 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 |
172173

173174
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.
174175

‎tests/test_known_differences.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,23 @@ def test_row_order_after_drop_duplicates():
7171
assert fd.apply_plan(pd.DataFrame(data), fd.suggest_plan(pd.DataFrame(data), cfg), cfg)["k"].tolist() == [3, 1, 2]
7272
lf = pl.LazyFrame(data)
7373
assert "UNIQUE[maintain_order: false" in fd.apply_plan(lf, fd.suggest_plan(lf, cfg), cfg).explain()
74+
75+
76+
def _count_collects(monkeypatch, lf, plan):
77+
calls = []
78+
real = pl.LazyFrame.collect
79+
monkeypatch.setattr(pl.LazyFrame, "collect", lambda self, *a, **k: calls.append(1) or real(self, *a, **k))
80+
out = fd.apply_plan(lf, plan)
81+
assert isinstance(out, pl.LazyFrame)
82+
return len(calls)
83+
84+
85+
def test_pandas_plan_with_currency_runs_one_query_on_a_lazyframe(monkeypatch):
86+
assert "pandas-made plan" in SECTION
87+
assert "Polars-made plan" in README.split("---", 1)[0]
88+
data = {"price": ["$10.00", "$20.00", "$30.00"]}
89+
pandas_plan = fd.suggest_plan(pd.DataFrame(data))
90+
polars_plan = fd.suggest_plan(pl.DataFrame(data))
91+
assert "parse_currency" in [a.action for a in pandas_plan.actions]
92+
assert _count_collects(monkeypatch, pl.LazyFrame(data), pandas_plan) == 1
93+
assert _count_collects(monkeypatch, pl.LazyFrame(data), polars_plan) == 0

0 commit comments

Comments
 (0)