Skip to content

Added implode KDocs - #2178

Open
AndreiKingsley wants to merge 3 commits into
masterfrom
implode_kdocs
Open

AndreiKingsley wants to merge 3 commits into
masterfrom
implode_kdocs

Conversation

@AndreiKingsley

@AndreiKingsley AndreiKingsley commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1385

@AndreiKingsley AndreiKingsley changed the title implode kdocs Added implode KDocs Oct 22, 2026
@AndreiKingsley
AndreiKingsley marked this pull request as ready for review October 22, 2026 11:31

@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.

Thanks for the thorough KDocs — just one dropNA caveat to add inline before this can go in!

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=9639e615-fa9a-401f-948e-cb852fd397de

@ExcludeFromSources
internal interface ImplodeDocs {
/**
* @param [\dropNA] If `true`, removes {@include [NALink]} values (`null`, [Double.NaN] or [Float.NaN])

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.

Blocking: dropNA drops NA values per column, independently, so when several columns are imploded in one call their lists stop lining up. This KDoc (and the new implodeDropNA_properties sample that illustrates it, which implodes city and year together) presents it as a harmless filter.

Failure scenario (verified on this branch): rows ("Alice", null, 2020), ("Alice", "Milan", 2021); df.implode(dropNA = true) { city and year } yields city = [Milan], year = [2020, 2021]. Calling the documented reverse operation, explode { city and year }, gives (Milan, 2020) and (null, 2021) — Milan is silently re-paired with the wrong year, no error. A user following this doc corrupts cross-column row correspondence.

Suggested fix: add a sentence to DropNASnippet stating that values are removed from each imploded column independently, so lists in different imploded columns may lose their positional correspondence and the explode roundtrip is then not value-preserving; and implode a single column in the dropNA sample so the example doesn't teach the multi-column form.

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 restructure the sentence a bit :) "removes NA values", who removes them? the function? You can also write "are removed" if that makes sense

@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.

Looks great — the KDocs match the implementation and the website page, and all four samples pass. 🎉


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=fb0fc889-be0e-4f3f-8b28-1abb7e96b087

@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.

Correcting my earlier approval — the blocking dropNA finding already posted inline does need addressing first, thanks!


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=fb0fc889-be0e-4f3f-8b28-1abb7e96b087

Comment thread core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/implode.kt
@Test
fun implodeDropNA_properties() {
// SampleStart
// Same as above, but `null` cities are removed from the lists

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 user reading the KDoc won't know that there are no null years, but that's the price of unification of samples :)

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.

Added tables

@AndreiKingsley

Copy link
Copy Markdown
Collaborator Author

@Allex-Nik added KDocs tables

@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.

Thanks for the fixes — one more dropNA caveat to add inline, then this is good to go!


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=ba455033-b2f2-4d24-bff0-3d571c73858f

internal interface ImplodeDocs {
/**
* @param [\dropNA] If `true`, removes {@include [NALink]} values (`null`, [Double.NaN] or [Float.NaN])
* from the merged lists. `false` by default.

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.

Blocking: dropNA only applies to value columns. implodeImpl filters just ColumnKind.Value; ColumnKind.Group goes through extractDataFrame() and ColumnKind.Frame through concat(), both unfiltered. This KDoc (and the one at line 30) states unconditionally that NA values are removed.

Failure scenario (verified on this branch): dataFrameOf("key" to listOf("a", "a"), "city" to listOf("London", null), "weight" to listOf(54, null)).group { city and weight }.into("info").implode(dropNA = true) { info } returns a nested frame with 2 rows — the all-NA row is still there. The linked website page's own example implodes a column group (df.implode { name and age and weight and isHappy }), so a user adding dropNA = true to it gets weight cleaned and name untouched, with no error and nothing in the docs explaining why.

Suggested fix: add to DropNASnippet (and the overview sentence) that dropNA affects only value columns — imploded column groups and frame columns keep all their rows regardless.

*
* Imploded columns will change their types:
* - `T` to `List<T>`;
* - [DataRow] to [DataFrame] — an imploded [ColumnGroup] is converted into a [FrameColumn].

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.

shouldn't that last one get a new line?

Comment thread core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/implode.kt
@ExcludeFromSources
internal interface ImplodeDocs {
/**
* @param [\dropNA] If `true`, removes {@include [NALink]} values (`null`, [Double.NaN] or [Float.NaN])

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 restructure the sentence a bit :) "removes NA values", who removes them? the function? You can also write "are removed" if that makes sense


/**
* @return A new [DataFrame] with one row per distinct combination of values in the other columns,
* where the [\columns] contain merged lists of values.

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 *specified columns

*
* If [dropNA] is `true`, {@include [NALink]} values are removed from the merged lists.
*
* It is the same as `df.implode(dropNA) { all() }[0]`.

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.

.single() might be better, actually. It signalizes implode turns the df into a single row (and it's safer)

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.

Add KDoc for Implode

3 participants