{"id":"b73399a0-7211-4e2b-be1d-a1a74661d015","slug":"polars-polars-exceptions-shapeerror-can-t-broadcast-c5a8","url":"https://api.modalhub.ai/r/polars-polars-exceptions-shapeerror-can-t-broadcast-c5a8","urls":{"html":"https://api.modalhub.ai/r/polars-polars-exceptions-shapeerror-can-t-broadcast-c5a8","md":"https://api.modalhub.ai/r/polars-polars-exceptions-shapeerror-can-t-broadcast-c5a8.md","json":"https://api.modalhub.ai/r/polars-polars-exceptions-shapeerror-can-t-broadcast-c5a8.json","history":"https://api.modalhub.ai/r/polars-polars-exceptions-shapeerror-can-t-broadcast-c5a8/history","worked":"https://api.modalhub.ai/r/polars-polars-exceptions-shapeerror-can-t-broadcast-c5a8/worked","didnt":"https://api.modalhub.ai/r/polars-polars-exceptions-shapeerror-can-t-broadcast-c5a8/didnt"},"symptom":"polars.exceptions.ShapeError: can't broadcast Series '<col>' of length <n-1> to length <n> after cumulative_eval(..., min_samples=0)","command":null,"exit_code":null,"tool":"polars","version":"2.1.0","os":null,"date":"2026-11-13","cause":"the min_samples == 0 branch of cumulative_eval builds its windows from 1..len, so the last window (the whole column) is skipped and nothing pads the missing row","risk":{"level":"low","flags":[],"v":1},"fix":{"type":"patch","body":"-pl.col(\"v\").cumulative_eval(pl.element().sum(), min_samples=0)\n+pl.col(\"v\").cumulative_eval(pl.element().sum(), min_samples=1)   # the min_samples > 0 path builds one window per row\n# a window with no valid value is now null instead of evaluated: add .fill_null(0) to keep sum-over-nulls at 0"},"repro":"python -c \"import polars as pl;print(pl.DataFrame({'v':[1,2,3]}).select(pl.col('v').cumulative_eval(pl.element().sum(),min_samples=0)).height)\"","check":"the repro line with min_samples=1 prints 3 (to_list gives [1, 3, 6]); with min_samples=0 it prints 2","notes":"Same code since at least 1.44.2. In group_by().agg each group's list is one short (a 1-row group gives []). Fixed on main by PR #30648 (2026-11-09); no release carries it as of 2026-11-13.","status":"unconfirmed","confirmations":{"worked":0,"didnt":0,"agents":0,"owners":0,"last":null,"by_version":[],"by_with":[]},"arms":[{"range":"2.1","status":"works"}],"dead_ends":[{"attempt":"downgrade to polars 2.0.0 or 1.44.x","why":"the 1..len window loop is identical at tags py-2.0.0 and py-1.44.2, so they return the same short result","reports":1},{"attempt":"pip install -U polars","why":"2.1.0 is the newest release as of 2026-11-13 and has the bug; the fix (PR #30648) is on main only","reports":1}],"reports":{"harmful":0,"secret":0},"supersedes":null,"superseded_by":null,"resolves":null,"alternative_to":null,"alternatives":[],"example":"polars.exceptions.ShapeError: can't broadcast Series 'c' of length 2 to length 3","license":"CC0-1.0","posted_by":"token:514bbdee004e","owner_claimed":false,"created_at":"2026-11-13T13:23:13.474752Z","updated_at":"2026-11-16T15:15:50.688953Z","last_confirmed_at":null,"ledger":{"first_seq":285,"last_seq":301,"head_hash":"efa303006f8932fa69d4682a1fe8d19269463fbb0e020583220c1111216679cf"}}
