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

feat: register 'set_sorted' as batch/elementwise #13896

Merged
merged 1 commit into from
Jan 22, 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
3 changes: 2 additions & 1 deletion crates/polars-plan/src/dsl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,8 @@ impl Expr {
/// This can lead to incorrect results if this `Series` is not sorted!!
/// Use with care!
pub fn set_sorted_flag(self, sorted: IsSorted) -> Expr {
self.apply_private(FunctionExpr::SetSortedFlag(sorted))
// This is `map`. If a column is sorted. Chunks of that column are also sorted.
self.map_private(FunctionExpr::SetSortedFlag(sorted))
}

#[cfg(feature = "row_hash")]
Expand Down
8 changes: 8 additions & 0 deletions py-polars/tests/unit/operations/test_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,11 @@ def test_slice_nullcount(ref: list[int | None]) -> None:
assert s.null_count() == sum(x is None for x in ref)
assert s.slice(64).null_count() == sum(x is None for x in ref[64:])
assert s.slice(50, 60).slice(25).null_count() == sum(x is None for x in ref[75:110])


def test_slice_pushdown_set_sorted() -> None:
ldf = pl.LazyFrame({"foo": [1, 2, 3]})
ldf = ldf.set_sorted("foo").head(5)
plan = ldf.explain()
# check the set sorted is above slice
assert plan.index("set_sorted") < plan.index("SLICE")
Loading