-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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(rust, python): add maintain_order
argument to sort
/top_k
/bottom_k
#9672
feat(rust, python): add maintain_order
argument to sort
/top_k
/bottom_k
#9672
Conversation
maintain_order
argument to sort
/top_k
/bottom_k
maintain_order
argument to sort
/top_k
/bottom_k
maintain_order
argument to sort
/top_k
/bottom_k
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for going through the code churn. This looks good. Can you add the mentioned comment in all docstrings?
You must also ensure we don't convert to streaming if this flag is set as the streaming API will not have a stable sort.
@@ -1236,6 +1249,8 @@ def bottom_k( | |||
per column by passing a sequence of booleans. | |||
nulls_last | |||
Place null values last. | |||
maintain_order | |||
Whether the order should be maintained if elements are equal. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a note that this is more expensive and blocks streaming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Done, not quite sure why the python test fails, is this known to be a fluky test? Edit: Ah, I added |
polars/polars-core/src/frame/mod.rs
Outdated
) -> PolarsResult<&mut Self> { | ||
println!("In sort in place"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A rogue print
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -3,6 +3,10 @@ use polars_plan::prelude::*; | |||
|
|||
pub(super) fn is_streamable_sort(args: &SortArguments) -> bool { | |||
// check if slice is positive | |||
if args.maintain_order { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't print here. And can we combine the check with the slice check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -97,7 +97,7 @@ pub fn hist(s: &Series, bins: Option<&Series>, bin_count: Option<usize>) -> Resu | |||
|
|||
cuts.left_join(&out, [category_str], [category_str])? | |||
.fill_null(FillNullStrategy::Zero)? | |||
.sort(["category"], false) | |||
.sort(["category"], false, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I think of this, I think we should make a struct
called something like SortOptions
that implements Default
. That should make calling this from the rust side much more ergonomic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that this is something for this PR?
We already have SortOptions
(s. here) and also the possibility to sort_with_options
. The difference between sort
and sort_with_options
is that we cannot specify multiple descending
columns in sort_with_options
(e.g. this is not possible with sort_with_options
). I guess a generalization of SortOptions
might be needed for this, but I don't see this in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason I propose this is because the number of arguments are becoming unwieldy and that can be resolved with an argument struct. Would you be willing to make a follow up PR on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, already thought about that. I think I might need some guidance on how to best do this design-wise but I can do the implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just created an issue for this: #9820
7bd6fdb
to
1b0a875
Compare
Alright, can you do a rebase @CloseChoice? Then we can do the argument struct in a later PR. |
a19277e
to
e1fdfb1
Compare
Thanks @CloseChoice |
closes #9401