Skip to content

Sort by docs fix - #2089

Open
AndreiKingsley wants to merge 11 commits into
masterfrom
sortBy_docs_fix
Open

AndreiKingsley wants to merge 11 commits into
masterfrom
sortBy_docs_fix

Conversation

@AndreiKingsley

Copy link
Copy Markdown
Collaborator

Updated .desc() -> .reversed().

Uses new guideline and skill from #2083

@AndreiKingsley

Copy link
Copy Markdown
Collaborator Author

Do not merge before #2083!

@AndreiKingsley

AndreiKingsley commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator Author

Please review only sortBy/sortWith pages update!
Guideline/skill review should be in #2083; this RR is their testing.

@jetbrains-air jetbrains-air Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread docs/StardustDocs/topics/sortWith.md Resolved
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/).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not just "comparable", but also "mutually comparable"


Returns a new [`DataFrame`](DataFrame.md) with the same rows, reordered according to the selected columns.

```kotlin

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also here you write :DataFrame without <T>, but below, column.sort(): DataColumn<T>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparable<T>


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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

link to column set?

// Sort rows by the full name length
df.sortBy { expr { name.firstName.length + name.lastName.length } }
// SampleEnd
.defaultHeaderFormatting { name }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does name itself need to be colored? I'd say only firstName and lastName

Comment on lines +45 to +48
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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Allex-Nik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left just a couple of small remarks, otherwise cool!

Discover `sortWith` operation for Kotlin DataFrame.
</link-summary>

## sortWith

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 } }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also String API?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants