Repository navigation
fix: keep DuckDB and Polars results out of pandas unless requested - #191
Merged
Merged
Conversation
Contributor
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
DuckDB (#52): output_format="arrow" / "polars" fetched every result with fetchdf() and then converted the pandas frame again. Fetch directly with to_arrow_table() (fetch_arrow_table() on older duckdb) or .pl() instead, keeping fetchdf() for pandas output and when the native semantic stage, which does not accept Arrow tables, runs afterwards. _frame_stats learns pyarrow tables and _convert_output passes them through. Polars (#53): duplicate detection and dedup counted rows with plain .collect() calls that re-evaluate the whole upstream plan in memory. Route them through the streaming collect path via a new _count helper; _collect now accepts engine_config=None (streaming default).
kevincostner17
force-pushed
the
fix/out-of-core-fetch
branch
from
September 14, 2026 17:50
7c6f4d1 to
d10a1cf
Compare
FreshData benchmark report —
|
| fixture | n_rows | n_cols | p50 s | p95 s | peak MB | repair % | false-repair % | preserve % | trust | monotonic | export % |
|---|
Authored-code reduction (Metric 6)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #52. Addresses #53.
Summary
#52 — DuckDB: with
engine="duckdb", every non-native output format ranconn.execute(sql).fetchdf(). Arrow or Polars output then converted that pandas frame a second time (pa.Table.from_pandas/pl.from_pandas), so the whole result sat in memory twice for callers who never asked for pandas.#53 — Polars: the dedup stage still counted rows with a plain
lf.select(pl.len()).collect(), three times: before dedup, for duplicate detection, and after dedup. Each count re-evaluated the entire upstream plan in memory instead of streaming.Changes
execution/backends/_duckdb.py: the pipeline returns an unfetched relation; the engine then fetches in the requested format:arrow→to_arrow_table(), orfetch_arrow_table()on older duckdb. In duckdb 1.5.arrow()returns aRecordBatchReader, so it isn't used.polars→.pl()pandas→fetchdf(), unchanged.semantic_enabled,fetchdf()is kept, because the native semantic stage accepts pandas, Polars and DuckDB relations but not Arrow tables.execution/_report.py:_frame_statshandlespyarrow.Table(rows, columns, null count,nbytes).execution/__init__.py:_convert_outputpasses an Arrow table straight through.execution/backends/_polars.py: new_count()sends row counts through_collect(), the streaming path whenEngineConfig.streaming._collectnow acceptsengine_config=None, treated as the streaming default.Not changed
Subset dedup still uses
unique(maintain_order=True), and the report still says that stage evaluates eagerly. I tried awith_row_index+min().over(subset)filter, butexplain(engine="streaming")didn't show it streaming any better thanunique, so the added complexity wasn't justified. I left #53 open for that part.Behaviour note
Arrow output from DuckDB now keeps DuckDB's native column types instead of going through pandas dtypes, e.g.
DECIMALstaysdecimal128instead of becomingfloat64. The values match the pandas path. This is noted in the CHANGELOG.Tests
New
tests/test_execution/test_out_of_core_fetch.py(12 cases):arrow/polarsoutput never callsfetchdf()/df()(both are patched to raise), and the report's row and column counts match the result.missing_afterandduplicates_removedmatch.engine="streaming"when streaming is on, and a plain collect when it is off, for both detection and removal.keep="first"/"last": same frame,duplicates_removedandrows_after.Results:
pytest tests/test_execution tests/test_backend_honesty.py tests/test_engine_duplicates.py tests/test_semantic_cleaning.pyplus the new file: all pass.ruff checkandmypy src/freshdata: clean.make truthbench-pr:backend_parity_comparison: pass, "no gate-level changes vs baseline",overall: PASS.