Kotlin / Kotlin/dataframe

Add docs and tests for `frames` pivot aggregation

Open
#1,963 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

KDocs tests
Dominant language
Kotlin
Stars
1.1k
Forks
83
Avg merge
4d 12h
Merged PRs (30d)
30

Description

Add docs and tests for frames pivot aggregation

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/frames.kt contains two small public APIs without KDocs and without dedicated unit tests:

  • Pivot<T>.frames(): DataRow<T>
  • PivotGroupBy<T>.frames(): DataFrame<T>

The function is briefly mentioned on the pivot site page in the aggregation grammar and examples:
https://kotlin.github.io/dataframe/pivot.html#examples-of-aggregation

What it does

frames() aggregates pivot groups without reducing their rows. Each pivot key becomes a resulting column, and the corresponding grouped rows are stored as frame values.

For Pivot, the result is a DataRow.

For PivotGroupBy, the result is a DataFrame with one row per grouping key.

Scope
  • Add concise KDocs for both frames() overloads in frames.kt.
  • Add one basic unit test for Pivot.frames().
  • Improve the pivot site docs with a short explanation, input/output tables, and a runnable example for frames().
Suggested KDoc content
/**
 * Aggregates this [Pivot] by keeping each pivot group as a frame.
 *
 * Each pivot key becomes a column in the resulting [DataRow], and each value is
 * a [DataFrame] containing rows that belong to the corresponding pivot group.
 */

For PivotGroupBy.frames(), use the same idea but mention that the result is a DataFrame
with one row per grouping key.

Basic test scenario
  • Given a dataframe with a Boolean pivot column, e.g. isHappy.
  • When calling df.pivot { isHappy }.frames().
  • Then the result contains columns for pivot keys, e.g. true and false.
  • And each resulting value is a dataframe with rows belonging to that pivot group.
Test sketch
@Test
fun `pivot frames keeps pivot groups as frame values`() {
    val df = dataFrameOf("name", "isHappy", "age")(
        "Alice", true, 20,
        "Bob", false, 30,
        "Charlie", true, 40,
    )

    val result = df.pivot("isHappy").frames()

    result.columnNames() shouldBe listOf("true", "false")

    val happy = result["true"] as DataFrame<*>
    val unhappy = result["false"] as DataFrame<*>

    happy.rowsCount() shouldBe 2
    unhappy.rowsCount() shouldBe 1
}
Acceptance criteria
  • Pivot.frames() and PivotGroupBy.frames() have KDocs.
  • There is at least one dedicated unit test for frames().
  • The pivot documentation includes a clear frames() example with input/output tables.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/frames.kt and review the existing pivot aggregation tests before adding coverage for both pivot-key results and grouped frame values. Update the pivot site page at the aggregation examples section with the requested explanation, tables, and runnable example. Done means both overloads have KDocs, a dedicated unit test passes, and the site documentation includes a clear frames() example.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
documentation, testing
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.