Skip to content

Flag an Expr as "sorted"

Source code

Description

This enables downstream code to use fast paths for sorted arrays. WARNING: this doesn’t check whether the data is actually sorted, you have to ensure of that yourself.

Usage

<Expr>$set_sorted(..., descending = FALSE)

Arguments

Ignored.
descending Sort the columns in descending order.

Value

Expr

Examples

library(polars)

# correct use flag something correctly as ascendingly sorted
s = pl$select(pl$lit(1:4)$set_sorted()$alias("a"))$get_column("a")
s$flags
#> $SORTED_ASC
#> [1] TRUE
#> 
#> $SORTED_DESC
#> [1] FALSE
# incorrect use, flag something as not sorted ascendingly
s2 = pl$select(pl$lit(c(1, 3, 2, 4))$set_sorted()$alias("a"))$get_column("a")
s2$sort()
#> polars Series: shape: (4,)
#> Series: 'a' [f64]
#> [
#>  1.0
#>  3.0
#>  2.0
#>  4.0
#> ]
s2$flags # returns TRUE while it's not actually sorted
#> $SORTED_ASC
#> [1] TRUE
#> 
#> $SORTED_DESC
#> [1] FALSE