Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix chunks
Browse files Browse the repository at this point in the history
ritchie46 committed Jun 7, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 0460731 commit 2b185c6
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crates/polars-core/src/chunked_array/ops/sort/arg_sort.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use polars_utils::iter::EnumerateIdxTrait;

use super::*;

// Reduce monomorphisation.
@@ -83,8 +81,13 @@ where
{
let mut vals = Vec::with_capacity(len);

let mut count: IdxSize = 0;
for arr_iter in iters {
vals.extend(arr_iter.into_iter().enumerate_idx());
vals.extend(arr_iter.into_iter().map(|v| {
let idx = count;
count += 1;
(idx, v)
}));
}

sort_impl(vals.as_mut_slice(), options);
12 changes: 12 additions & 0 deletions py-polars/tests/unit/operations/test_sort.py
Original file line number Diff line number Diff line change
@@ -1000,3 +1000,15 @@ def test_sort_nan_1942() -> None:
end = time.time()

assert (end - start) < 1.0


def test_sort_chunked_no_nulls() -> None:
df = pl.DataFrame({"values": [3.0, 2.0]})
df = pl.concat([df, df], rechunk=False)

assert df.with_columns(pl.col("values").arg_sort())["values"].to_list() == [
1,
3,
0,
2,
]

0 comments on commit 2b185c6

Please sign in to comment.