Skip to content

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

Description

@koperagen

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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions