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

Clarify meaning of multiple arguments to set_sorted #20695

Open
mdavis-xyz opened this issue Jan 13, 2025 · 1 comment · May be fixed by #20709
Open

Clarify meaning of multiple arguments to set_sorted #20695

mdavis-xyz opened this issue Jan 13, 2025 · 1 comment · May be fixed by #20709
Labels
documentation Improvements or additions to documentation

Comments

@mdavis-xyz
Copy link
Contributor

Description

set_sorted allows multiple columns to be passed. It's not clear whether this refers to join sorting or individual sorting.

e.g. consider this dataframe:

┌─────┬─────┐
│ x   ┆ y   │
│ --- ┆ --- │
│ i64 ┆ i64 │
╞═════╪═════╡
│ 1   ┆ 1   │
│ 1   ┆ 2   │
│ 2   ┆ 1   │
│ 2   ┆ 2   │
└─────┴─────┘

If you look at column y on it's own, the third row has a smaller value (1) than the second row (2), so it's not sorted. However if you call .sort("x", "y") on this dataframe, this is the result you will get.

Which meaning of "sorted" is used here?

Link

https://docs.pola.rs/api/python/stable/reference/lazyframe/api/polars.LazyFrame.set_sorted.html#polars.LazyFrame.set_sorted

@mdavis-xyz mdavis-xyz added the documentation Improvements or additions to documentation label Jan 13, 2025
@mcrumiller
Copy link
Contributor

set_sorted allows multiple columns to be passed.

The docstring is bad, this is not true. set_sorted only allows a single column name.

import polars as pl
pl.DataFrame({"a": [1], "b": [2]}).set_sorted(["a", "b"])
# TypeError: expected a 'str' for argument 'column' in 'set_sorted'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants