polars.Expr.set_sorted#

Expr.set_sorted(*, descending: bool = False) Self[source]#

Flags the expression as ‘sorted’.

Enables downstream code to user fast paths for sorted arrays.

Parameters:
descending

Whether the Series order is descending.

Warning

This can lead to incorrect results if this Series is not sorted!! Use with care!

Examples

>>> df = pl.DataFrame({"values": [1, 2, 3]})
>>> df.select(pl.col("values").set_sorted().max())
shape: (1, 1)
┌────────┐
│ values │
│ ---    │
│ i64    │
╞════════╡
│ 3      │
└────────┘