Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Sep 5, 2024
1 parent af8738c commit fb68803
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ impl OptimizationRule for SimpleProjectionAndCollapse {
input,
by_column,
slice,
sort_options,
sort_options:
sort_options @ SortMultipleOptions {
maintain_order: false, // `maintain_order=True` is influenced by result of earlier sorts
..
},
} => match lp_arena.get(*input) {
Sort {
input: inner,
Expand Down
21 changes: 21 additions & 0 deletions py-polars/tests/unit/lazyframe/optimizations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
import polars as pl
from polars.testing import assert_frame_equal


def test_remove_double_sort() -> None:
assert (
pl.LazyFrame({"a": [1, 2, 3, 3]}).sort("a").sort("a").explain().count("SORT")
== 1
)


def test_double_sort_maintain_order_18558() -> None:
df = pl.DataFrame(
{
"col1": [1, 2, 2, 4, 5, 6],
"col2": [2, 2, 0, 0, 2, None],
}
)

lf = df.lazy().sort("col2").sort("col1", maintain_order=True)

expect = pl.DataFrame(
[
pl.Series("col1", [1, 2, 2, 4, 5, 6], dtype=pl.Int64),
pl.Series("col2", [2, 0, 2, 0, 2, None], dtype=pl.Int64),
]
)

assert_frame_equal(lf.collect(), expect)

0 comments on commit fb68803

Please sign in to comment.