Skip to content
This repository has been archived by the owner on Jan 28, 2023. It is now read-only.

df.sortedByDescending(...) produces unexpected (unsorted) results #44

Closed
icedraco opened this issue Mar 28, 2018 · 1 comment
Closed

Comments

@icedraco
Copy link

I've been getting unusual results from DataFrame.sortedByDescending() whereas sortedBy() worked as expected. The following two examples were taken from the main page here and slightly augmented. I wanted to sort dataframe rows by the "weight" column in descending order:

Example (Integers)

fun main(args: Array<String>) {
    val df = dataFrameOf("first_name", "last_name", "age", "weight")(
            "Max", "Doe", 23, 55,
            "Franz", "Smith", 23, 10,
            "Horst", "Keanes", 12, 0,
            "Horst", "Keanes", 12, 0,
            "Horst", "Keanes", 12, 1,
            "Horst", "Keanes", 12, 50,
            "Horst", "Keanes", 12, 2
    )

    df.sortedByDescending("weight").print()
}

Result

A DataFrame: 7 x 4
first_name   last_name   age   weight
       Max         Doe    23       55
     Horst      Keanes    12        0
     Horst      Keanes    12        2
     Horst      Keanes    12       50
     Horst      Keanes    12        1
     Franz       Smith    23       10
     Horst      Keanes    12        0

Example (Double + negative)

fun main(args: Array<String>) {
    val df = dataFrameOf("first_name", "last_name", "age", "weight")(
            "Max", "Doe", 23, 55.0,
            "Franz", "Smith", 23, -10.0,
            "Horst", "Keanes", 12, 0.0,
            "Horst", "Keanes", 12, 0.10,
            "Horst", "Keanes", 12, 1.0,
            "Horst", "Keanes", 12, -0.05,
            "Horst", "Keanes", 12, -0.02
    )

    df.sortedByDescending("weight").print()
}

Result

A DataFrame: 7 x 4
first_name   last_name   age   weight
       Max         Doe    23       55
     Horst      Keanes    12    -0.02
     Horst      Keanes    12      0.1
     Horst      Keanes    12        0
     Franz       Smith    23      -10
     Horst      Keanes    12    -0.05
     Horst      Keanes    12        1

In both cases, the "weight" column in the printout is different, but not sorted at all. In case of sortedBy(), the "weight" column was properly sorted...

This looks like a bug to me.

@holgerbrandl
Copy link
Owner

Indeed. My initial impl was wrong because I could not properly get my head around the difference between order and rank, and also struggled to mix this with the kotlin stdlib. Now, my fix is progressing well including more tests to prevent future regressions.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants