Repository navigation
Sort by docs fix - #2089
Sort by docs fix#2089AndreiKingsley wants to merge 11 commits into
Conversation
|
Do not merge before #2083! |
|
Please review only sortBy/sortWith pages update! |
There was a problem hiding this comment.
Nice, much clearer sort docs — one blocking item inline to fix before merge.
Produced by Air Automations. Name: AI Review / Run: https://air.jetbrains.cloud/org/05cf1a7f-6ab5-713b-abd3-29d0c8a05e2d/automations/8daf2412-0b6c-4433-90c0-b40ab5aebcdb?run=aad710e9-18a0-40d5-a628-edd016816b63
| The order in which columns are selected defines the sort priority: | ||
| rows are compared by the first selected column, ties are resolved by the second one, and so on. | ||
|
|
||
| Column values must be [`Comparable`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-comparable/). |
There was a problem hiding this comment.
not just "comparable", but also "mutually comparable"
|
|
||
| Returns a new [`DataFrame`](DataFrame.md) with the same rows, reordered according to the selected columns. | ||
|
|
||
| ```kotlin |
There was a problem hiding this comment.
not exactly our grammar notation... It's okay and understandable, but it's a bit of a mix between kotlin and grammar, may be a bit odd
There was a problem hiding this comment.
also here you write :DataFrame without <T>, but below, column.sort(): DataColumn<T>
There was a problem hiding this comment.
I like this notation more — it's easier to understand argument and result types, isn't it? It also looks closer to our KDocs Grammar.
| ``` | ||
|
|
||
| Takes no parameters and accepts only columns whose value type `T` is | ||
| [`Comparable`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-comparable/). |
|
|
||
| It's available in the `sortBy { }` and `sortByDesc { }` overloads that take a lambda; | ||
| the overloads that take [string column names](concepts/StringApi.md) always sort | ||
| in the default direction of the operation. |
There was a problem hiding this comment.
what's the default direction? where are nulls placed by default?
|
|
||
| ### reversed | ||
|
|
||
| `.reversed()` reverses the sort order for a single column or a column set: |
| // Sort rows by the full name length | ||
| df.sortBy { expr { name.firstName.length + name.lastName.length } } | ||
| // SampleEnd | ||
| .defaultHeaderFormatting { name } |
There was a problem hiding this comment.
does name itself need to be colored? I'd say only firstName and lastName
| This operation doesn't select columns, so it has neither | ||
| [string column names](concepts/StringApi.md) nor | ||
| [Columns Selection DSL](ColumnSelectors.md) overloads: the whole row is available inside | ||
| the comparator, and any of its columns can be used there. |
There was a problem hiding this comment.
hmm maybe... but it seems a bit out of place to have a paragraph of information about what this function does not have
Allex-Nik
left a comment
There was a problem hiding this comment.
Left just a couple of small remarks, otherwise cool!
| Discover `sortWith` operation for Kotlin DataFrame. | ||
| </link-summary> | ||
|
|
||
| ## sortWith |
There was a problem hiding this comment.
With this, there are two sortWith titles (one next to another) on the page itself and in its content
|
|
||
| ```kotlin | ||
| // Sort rows by the full name length | ||
| df.sortBy { expr { name.firstName.length + name.lastName.length } } |
There was a problem hiding this comment.
Do we need the String API version here as well?
|
|
||
| * `comparator: Comparator<DataRow>` — a comparator of [`DataRow`](DataRow.md)s of this | ||
| [`DataFrame`](DataFrame.md) that defines the order of rows. | ||
| * `{ row1: DataRow, row2: DataRow -> Int }` — the same comparator given as a lambda: |
There was a problem hiding this comment.
The guidelines suggest the form expression: (DataRow) -> Value.
So in this case it would mean comparator: (DataRow, DataRow) -> Int, right?
The way it is shown on this page is more intuitive maybe
|
|
||
| ```kotlin | ||
| // Sort "name"/"lastName" values by their length | ||
| df.name.lastName.sortWith { name1, name2 -> name1.length - name2.length } |
Updated
.desc()->.reversed().Uses new guideline and skill from #2083