Kotlin / Kotlin/dataframe

List of all nulls (Nothing? type) produces unexpected ColumnGroup column kind instead of ValueColumn

Open Beginner friendly
#2,034 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Minimal repro:

fun main() {
    val df2 = dataFrameOf(
        "nulls" to List(3) { null }.toColumn(),
    )
}

Expected:
one value column
nulls: Nothing?

Actual:
Nothing? gets picked up by this.isSubtypeOf(typeOf<AnyRow?>()) -> ColumnKind.Group branch

internal fun KType.toColumnKind(): ColumnKind =
    when {
        this.isSubtypeOf(typeOf<AnyFrame>()) -> ColumnKind.Frame
        this.isSubtypeOf(typeOf<AnyRow?>()) -> ColumnKind.Group
        else -> ColumnKind.Value
    }

This leads to strange side effects like this pretty normal looking code failing with exception:

val df2 = dataFrameOf(
    "nulls" to List(3) { null }.toColumn(),
    "lists" to List(3) { n -> List(n) { n } }.toColumn()
)
df2.explode { lists }

Exception in thread "main" org.jetbrains.kotlinx.dataframe.exceptions.UnequalColumnSizesException: Unequal column sizes. Expected rows count: 0. Actual column sizes:
nulls: 0
lists: 3

Fix:
Just add a Nothing? -> Kind.Value branch

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 at the internal KType.toColumnKind() entry point shown in the issue and inspect nearby column-kind tests. Reproduce the all-null column example, then verify that it is treated as a value column and that the combined nulls/lists example can be exploded without unequal column sizes.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.