Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Don't rechunk by default in concat #16128

Merged
merged 4 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/polars-plan/src/logical_plan/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ impl Default for UnionArgs {
fn default() -> Self {
Self {
parallel: true,
rechunk: true,
rechunk: false,
to_supertypes: false,
diagonal: false,
from_partitioned_ds: false,
Expand Down
2 changes: 1 addition & 1 deletion py-polars/polars/functions/eager.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def concat(
items: Iterable[PolarsType],
*,
how: ConcatMethod = "vertical",
rechunk: bool = True,
rechunk: bool = False,
parallel: bool = True,
) -> PolarsType:
"""
Expand Down
4 changes: 2 additions & 2 deletions py-polars/polars/series/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -2902,7 +2902,7 @@ def chunk_lengths(self) -> list[int]:

Concatenate Series with rechunk = True

>>> pl.concat([s, s2]).chunk_lengths()
>>> pl.concat([s, s2], rechunk=True).chunk_lengths()
[6]

Concatenate Series with rechunk = False
Expand All @@ -2925,7 +2925,7 @@ def n_chunks(self) -> int:

Concatenate Series with rechunk = True

>>> pl.concat([s, s2]).n_chunks()
>>> pl.concat([s, s2], rechunk=True).n_chunks()
1

Concatenate Series with rechunk = False
Expand Down
4 changes: 2 additions & 2 deletions py-polars/tests/unit/dataframe/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,10 @@ def test_multiple_columns_drop() -> None:

def test_concat() -> None:
df1 = pl.DataFrame({"a": [2, 1, 3], "b": [1, 2, 3], "c": [1, 2, 3]})
df2 = pl.concat([df1, df1])
df2 = pl.concat([df1, df1], rechunk=True)

assert df2.shape == (6, 3)
assert df2.n_chunks() == 1 # the default is to rechunk
assert df2.n_chunks() == 1
assert df2.rows() == df1.rows() + df1.rows()
assert pl.concat([df1, df1], rechunk=False).n_chunks() == 2

Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/expr/test_exprs.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def test_expression_appends() -> None:
assert df.select(pl.repeat(None, 3).append(pl.col("a"))).n_chunks() == 2
assert df.select(pl.repeat(None, 3).append(pl.col("a")).rechunk()).n_chunks() == 1

out = df.select(pl.concat([pl.repeat(None, 3), pl.col("a")]))
out = df.select(pl.concat([pl.repeat(None, 3), pl.col("a")], rechunk=True))

assert out.n_chunks() == 1
assert out.to_series().to_list() == [None, None, None, 1, 1, 2]
Expand Down