Skip to content

Commit

Permalink
correct sort fast paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Nov 27, 2021
1 parent 2796f4e commit e4a25d0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion polars/polars-core/src/chunked_array/ops/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,27 @@ where
T::Native: Default,
{
fn sort_with(&self, options: SortOptions) -> ChunkedArray<T> {
if options.descending && self.is_sorted_reverse() || self.is_sorted() {
if self.is_empty() {
return self.clone();
}

if options.descending && self.is_sorted_reverse() || self.is_sorted() {
// there are nulls
if self.has_validity() {
// if the nulls are already last we can clone
if options.nulls_last && self.get(self.len() - 1).is_none() ||
// if the nulls are already fist we can clone
self.get(0).is_none()
{
return self.clone();
}
// nulls are not at the right place
// continue w/ sorting
// TODO: we can optimize here and just put the null as the correct place
} else {
return self.clone();
}
}
if !self.has_validity() {
let mut vals = memcpy_values(self);
sort_branch(
Expand Down

0 comments on commit e4a25d0

Please sign in to comment.