Exception in documentation example of `maxByOrNull`
In Operations/Access/Get Rows we have:
df.maxByOrNull { weight }
Executing this in a Kotlin Notebook cell results in: Type mismatch: inferred type is Int? but Int was expected
Gradle settings:
plugins {
kotlin("jvm") version "2.2.20-Beta1"
kotlin("plugin.dataframe") version "2.2.20-Beta1"
}
dependencies {
implementation("org.jetbrains.kotlinx:dataframe:1.0.0-Beta2")
testImplementation(kotlin("test"))
}
Also caused by https://github.com/Kotlin/dataframe/issues/1116
It's listed in the known issues for the release (https://github.com/Kotlin/dataframe/releases/tag/v1.0.0-Beta2) that for 1.0.0-Beta2 in notebooks "min, max, median, and percentile might not work". Stick to 1.0.0-dev-7089 if you want to use 1.0.0-Beta2 in notebooks for now.
Right, I can see that there is a lot of work in progress. Do note that this happens in 1.0.0-dev-7089 too.
Well yes, in the example, the weight column is nullable, so it's not allowed in notebooks in 1.0.0-dev-7089 with the maxByOrNull {} operation. That's what the error message says: "Type mismatch: inferred type is Int? but Int was expected".
What would work is something like: df.maxByOrNull { weight ?: 0 }.
But yes, the workaround is not very nice, so I hope https://youtrack.jetbrains.com/issue/KT-76441/IllegalStateException-null-DefinitelyNotNullType-for-T-exception-while-analyzing-expression gets fixed soon.
@Jolanrensen please revisit this also
https://github.com/Kotlin/dataframe/issues/1401#issuecomment-3616911559