dotnet / dotnet/machinelearning

DataFrame.OrderBy(string columnName) does not perform stable sorting!

Open
#6,443 1 comment 0 reactions 0 assignees View on GitHub
area-DataFrame bug in-pr
Dominant language
C#
Stars
9.4k
Forks
2k
Avg merge
2d 20h
Merged PRs (30d)
11

Description

Stable sorting preserves the order of entries in the input when their sorting keys are same. Please see the below link:
https://stackoverflow.com/questions/1517793/what-is-stability-in-sorting-algorithms-and-why-is-it-important

As an example:
Before sorting...

```
df
A B C
9 18 28
6 11 25
6 10 23
3 16 26
6 13 21
3 19 22
3 11 28
6 17 20
```

After sorting...

```
df.OrderBy("A")
A B C
3 16 26
3 11 28
3 19 22
6 11 25
6 10 23
6 17 20
6 13 21
9 18 28
```

The three rows where column `A` = `3`, should be ordered with column `B` as `16,19,11` (not `16,11,19`).
The four rows where column `A` = `6`, should be ordered with column `B` as `11,10,13,17` (not `11,10,17,13`).

If we get a stable sorting with `OrderBy` function, we would have a work-around for multi-column sorting which is not yet available according to [#5758](https://github.com/dotnet/machinelearning/issues/5758) and [#5649](https://github.com/dotnet/machinelearning/issues/5649). For those interested in the workaround, please see [this question on stackoverflow](https://stackoverflow.com/questions/24573337/c-sharp-deedle-sort-by-multiple-columns).

Thanks!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.