Skip to content

fix(server): page the whole frame for /load backend=polars (#992) - #1000

Closed
paddymul wants to merge 2 commits into
mainfrom
fix/992-pre-limit-false
Closed

paddymul wants to merge 2 commits into
mainfrom
fix/992-pre-limit-false

Conversation

@paddymul

@paddymul paddymul commented Oct 2, 2026

Copy link
Copy Markdown
Collaborator

Fixes #992.

Problem

/load with backend: "polars" pages a random 1M-row sample, shuffled, when the file has more rows. PolarsServerSampling.pre_limit = 1_000_000 (buckaroo/server/data_loading_polars.py) feeds Sampling.pre_stats_sample, which CustomizableDataflow.__init__ uses to build the dataflow's raw frame (dataflow.py:420), and pre_stats_sample returns df.sample(pre_limit). The sample becomes the table: every row request, sort and search runs against it, and df_meta reports filtered_rows: 1000000 against total_rows: 1200000.

The class docstring says pre_limit caps the stats work. It doesn't. PlDfStatsV2.get_operating_df already samples 50k rows (seed 42) for the stats pipeline whenever rows * cols exceeds FAST_SUMMARY_WHEN_GREATER, independent of pre_limit.

Approach

This is one of several candidate approaches for #992. It sets pre_limit = False on PolarsServerSampling, which PLSampling (the notebook polars widget) and XorqInfiniteSampling already do, so the dataflow's raw frame is the whole file in file order. Stats keep their existing 50k-row sample in PlDfStatsV2.

The alternative being tried in parallel keeps a row cap for the stats input but applies it only to what DFStatsClass reads, marking the stats as sampled, instead of replacing raw_df.

What changes

  • PolarsServerSampling.pre_limit goes from 1_000_000 to False; the docstring says what the class actually does.
  • Not touched: the pandas ServerSampling (buckaroo/server/data_loading.py) has the same pre_limit = 1_000_000. It sort_index()es the sample, so rows come back in file order there, but 200k of 1.2M rows are still dropped. That's a separate change.

Tests

  • tests/unit/server/test_data_loading_polars.py::test_dataflow_keeps_every_row_in_file_order: create_polars_dataflow on a 1.2M-row frame keeps all rows and the first window is rows 0..99.
  • tests/unit/server/test_server.py::TestLoad::test_load_polars_backend_keeps_every_row: POST /load with backend=polars on a 1.2M-row parquet answers rows: 1200000 and the session's df_meta has filtered_rows == total_rows == 1200000.

Trade-offs

A /load of a very large parquet now holds the whole frame in memory as the dataflow's raw_df and processed_df, instead of a 1M-row sample. That's the same memory profile as load_file_polars already has (it reads the file eagerly), so the cap only ever saved the dataflow's copy. Sorts and searches over the websocket now run over the full frame; the #999 measurements cover what that costs.

🤖 Generated with Claude Code

…sample (#992)

PolarsServerSampling.pre_limit = 1_000_000 makes pre_stats_sample hand
CustomizableDataflow a shuffled df.sample(1_000_000) as its raw frame,
so a file with more rows pages a random sample out of file order.
Covers create_polars_dataflow directly (row count and the first window's
order) and POST /load with backend=polars on a 1.2M-row parquet
(df_meta filtered_rows must equal total_rows).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

📦 TestPyPI package published

pip install --index-strategy unsafe-best-match --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ buckaroo==0.15.9.dev37080672845

or with uv:

uv pip install --index-strategy unsafe-best-match --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ buckaroo==0.15.9.dev37080672845

MCP server for Claude Code

claude mcp add buckaroo-table -- uvx --from "buckaroo[mcp]==0.15.9.dev37080672845" --index-strategy unsafe-best-match --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ buckaroo-table

📖 Docs preview

🎨 Storybook preview

PolarsServerSampling.pre_limit = 1_000_000 made pre_stats_sample hand
CustomizableDataflow a shuffled df.sample(1_000_000) as its raw frame,
so a file with more rows paged a random sample out of file order, and
every sort and search ran against it. pre_limit never capped the stats
work its docstring described: PlDfStatsV2.get_operating_df already
samples 50k rows for the stats pipeline.

pre_limit = False, as PLSampling and XorqInfiniteSampling already use,
keeps the whole frame in file order. The pandas ServerSampling keeps
its pre_limit for now; it sorts the sample, so order survives there,
but rows are still dropped.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@paddymul

paddymul commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator Author

Measurements

I ran the server from this branch (d52ddab) and from main (992fdb3), loading real files with POST /load {mode: "buckaroo", backend: "polars"} and reading the websocket. Each row below is the median of 5 runs, each with a fresh server process and a warm OS file cache. Scripts and raw per-run JSON are in the eval scratchpad (eval_992a_trial.py, eval_992a_out/runs.jsonl).

parking_2017.parquet (10,803,012 rows, 43 columns, 409 MB):

main this branch
/load response rows 10803012 10803012
initial_state df_meta filtered_rows / total_rows 1000000 / 10803012 10803012 / 10803012
first infinite_resp length 1000000 10803012
first 5 values of column 1 vs pl.scan_parquet(...).head(5) differ (5095291046, 1417195575, ...) equal (5092469481, 5092451658, 4631633384, 8196557280, 4631184358)
rows 0..100 in file order no, 5 of 5 runs yes, 5 of 5 runs
window at [total-10, total) 0 rows 10 rows, last 5 equal file tail
sort desc on column 1, first 5 vs polars differ (sorts the 1M sample) equal
POST /load response time 0.83 s 0.57 s
time from POST start to first infinite_resp 0.85 s 0.59 s
server RSS after load 6.9 GB 6.3 GB
peak server RSS through load and first window 6.9 GB 6.3 GB
sort desc request (10.8M rows on the branch, 1M rows on main) 0.06 s 3.6 s
peak server RSS during sort 7.0 GB 10.2 GB (settles to 2.6 GB after)

Idle server RSS before load is 165 MB in both.

8e98b80a36ef.parquet (52,814 rows, 27 columns). This file is below the old 1M cap, so it is a control and the two builds should match:

main this branch
rows / filtered_rows / total_rows / length 52814 everywhere 52814 everywhere
first 5 of column 1 equal file head yes yes
POST /load response time 0.80 s 0.78 s
server RSS after load 1.0 GB 1.0 GB
sort desc request 0.14 s 0.14 s

What varied with what:

  • Row counts, df_meta and ordering are determined by whether the file has more than 1,000,000 rows. Main drops to a shuffled 1M-row sample only above that threshold, and the branch never does for polars. The 52k-row file is identical on both.
  • Sort time scales with the number of rows sorted. Main sorts 1M rows, the branch sorts 10.8M, which accounts for the 0.06 s to 3.6 s change and the extra ~4 GB of peak RSS during the sort. The grid's sort now returns the true maximum (8585600044) where main returned a value from the sample (8585550053).
  • The first window and tail window reads are 6 to 7 ms on the branch for the 10.8M file, since they slice an in-memory frame.
  • RSS after load on main ranged 6.2 to 6.9 GB across the 5 runs. I did not isolate what moves it. The branch ranged 6.285 to 6.287 GB.

Every run returned no error_info, the server logs contain no tracebacks, and each server was stopped (nothing left listening on its port).

@paddymul

paddymul commented Oct 5, 2026

Copy link
Copy Markdown
Collaborator Author

Closed. sampling for in memory is a valid approach. We need to do out of core, something similar to lazyinfinitepolars to really address this

@paddymul paddymul closed this Oct 5, 2026
@paddymul paddymul added the buckaroo-server-polars Polars /load work on the buckaroo server (#992-#999), superseded by a scan_parquet backend label Oct 5, 2026

This branch was successfully deployed

1 active deployment
testpypi — d52ddabe Deployed Oct 3, 2026 by paddymul via Publish to TestPyPI #1616
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

buckaroo-server-polars Polars /load work on the buckaroo server (#992-#999), superseded by a scan_parquet backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server: /load with backend=polars pages a random 1M-row sample, shuffled, when the file has more rows

1 participant