Skip to content

Added KDocs, tests and website examples for unfold, fixed DataColumn.unfold - #2117

Merged
zaleslaw merged 3 commits into
masterfrom
issue-1991
Oct 1, 2026
Merged

zaleslaw merged 3 commits into
masterfrom
issue-1991

Conversation

@zaleslaw

Copy link
Copy Markdown
Collaborator

Closes #1991

unfold had no KDocs, its page had one example with a data: Any class, and two of three overloads had no tests.

This PR documents the three non-deprecated overloads, rewrites the page on the toDataFrame dataset, and fixes DataColumn.unfold on untyped columns.

Files

File What changed
core/.../api/unfold.kt KDocs for the three overloads, shared parts in UnfoldDocs
core/.../impl/api/unfold.kt DataColumn.unfold falls back to the column type when T cannot be unfolded
core/.../documentation/DocumentationUrls.kt Unfold link
core/src/test/.../api/unfold.kt tests for every documented claim; 4 @Ignored tests for #2114
samples/.../api/UnfoldSamples.kt, topics/unfold.md new page: unfold, maxDepth, roots, what stays as it is, unfold on DataColumn. Removed: the RepositoryInfo example, the "useful when" list and "a special case of convert" (see the note)
samples/.../plugin/UnfoldCompileTimeSchemaTests.kt compile-time schema vs runtime schema for unfold and toDataFrame; 3 @Ignored tests for #2114 and #2115
topics/_shadow_resources.md, resources/api/unfold/, samples/build.gradle.kts iframes of the page, page moved to :samples korro
topics/collectionsInterop.md, topics/updateConvert.md the sentence about unfold reworded to match the KDoc

Examples

The page, the KDocs and the tests use the classes and objects of the toDataFrame() example on createDataFrame.md (Student, Name, Score), so unfold(maxDepth = 1) shows the same structure as toDataFrame(maxDepth = 1) there.

Tests

Before, only the DataFrame overloads with default arguments and maxDepth were tested. All expected values come from a real run.

Test What it pins down
column group per property, name and place of the column constructor order, by name without a primary constructor, other columns unchanged
maxDepth 0 / 1 / 2 values stay as they are; nested objects → column groups, lists → frame columns; one level per step
roots only the given properties, getter-like functions too; ignored on a column of simple values
columns that stay as they are enums, classes without properties, Any, column groups, frame columns
null objects, several columns by name nulls in every new column, an empty dataframe in a frame column
DataColumn.unfold static type decides; Any falls back to the column type; the same column is returned when it cannot be unfolded

Note for the reviewer

  • Fixed: df["student"].unfold() (static type Any?) returned a column group with one column value holding the objects. Now it unfolds the objects by the column type. Test: DataColumn unfold reads the properties of the values when the static type is Any. The fallback lives in unfoldImpl, which is not inline, so already compiled callers get it too. A DataColumn<Supertype> still unfolds only the properties of the supertype.
  • Documented, not changed: roots are ignored on a column of simple values (unfold(String::length) { word } keeps the column); with roots, the compiler plugin derives an empty schema (Kotlin DataFrame plugin: unfold and toDataFrame with properties give an empty schema #2115).
  • Known issues, tests marked @Ignore with TODO(#2114) / TODO(#2115): roots of another class are stored as exceptions; a column of lists becomes { size }; a column of maps is unfolded; with property roots the compiler plugin derives an empty schema for unfold and toDataFrame.
  • Removed from unfold.md: the RepositoryInfo example. Its class had one property, data: Any, so the result was a group with one Any column and showed neither nesting, maxDepth nor roots; its use case ("a library API gives you class instances") is kept as a sentence. The item "you do not want to or cannot annotate classes with @DataSchema" is removed because annotating does not change anything here: columnOf and dataFrameOf keep @DataSchema objects in a ValueColumn, like any other objects. "It's a special case of convert" moved to "See also" as convert and replace.
  • core/.../samples/api/Modify.kt keeps the old convertToColumnGroup* samples; no page uses them anymore.

This commit introduces extensive examples and tests for the `unfold` API, showcasing its usage in various scenarios like unfolding column groups, nested objects, frame columns, and handling edge cases. Documentation resources and shadow resources have also been updated to reflect these additions.
@zaleslaw
zaleslaw requested a review from koperagen September 29, 2026 13:15

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

Comment thread core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/unfold.kt Outdated
Comment thread docs/StardustDocs/topics/unfold.md
Comment thread docs/StardustDocs/topics/unfold.md
@zaleslaw
zaleslaw marked this pull request as ready for review October 1, 2026 13:44
@zaleslaw
zaleslaw merged commit 80bd780 into master Oct 1, 2026
5 checks passed
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 KDocs for unfold APIs

2 participants