Skip to content

polars/polars-concat-in-loop

Rule polars-concat-in-loop
Pack Polars
Severity info
Fix none, edit by hand
Library versions every version

Concatenating into the same frame on every iteration repeatedly grows the result. Collect the pieces and concatenate once.

output = pl.concat([output, piece], rechunk=True)
output = pl.concat(pieces, rechunk=True)

16.23x and 269.11x on 50,000 and 500,000 total rows across 25 batches with rechunk=True.

Edit the code using the replacement in the example.

xpd prints this message with the issue. A name that starts with $ stands for code from your file.

Concatenating into the same frame on every iteration repeatedly grows the result. Collect the pieces and concatenate once.

Browse the other rules of the Polars pack.