Closed
Description
type: KType
in DataColumnImpl
mismatches actual values in some cases. This can result in runtime exceptions and makes life difficult attempting to fix #30 or #704 where we assume the type
always correctly represents the data.
This issue relates to #701 as well.
To discover these bugs, we can introduce a (debug-only!!) check in DataColumnImpl
, like:
private infix fun <T> T?.matches(type: KType) =
when {
this == null -> type.isMarkedNullable
this.isPrimitiveArray -> type.isPrimitiveArray &&
this!!::class.qualifiedName == type.classifier?.let { (it as KClass<*>).qualifiedName }
this.isArray -> type.isArray // cannot check the precise type of array
else -> this!!::class.isSubclassOf(type.classifier as KClass<*>)
}
init {
if (DEBUG) {
require(values.all { it matches type }) {
val types = values.map { if (it == null) "Nothing?" else it!!::class.simpleName }.distinct()
"Values of column '$name' have types '$types' which are not compatible given with column type '$type'"
}
}
}
At the moment of testing, I can find 8+ breaking tests in :core
:
org.jetbrains.kotlinx.dataframe.io.PlaylistJsonTest#aggregate by column
- data has types
[DataFrameImpl]
,kType
is:org.jetbrains.kotlinx.dataframe.aggregation.AggregateGroupedDsl<org.jetbrains.kotlinx.dataframe.io.PlaylistJsonTest.DataFrameType1>
- This exception is probably fine to ignore, as
AggregateGroupedDsl
is aDataFrame
- data has types
org.jetbrains.kotlinx.dataframe.samples.api.Analyze#pivotDefault_accessors
/#pivotDefault_strings
/#pivotDefault_properties
- data has types
[Boolean, Int]
,kType
is:kotlin.Boolean
- Not really sure what's going on here, something with
concatImpl
I think
- data has types
org.jetbrains.kotlinx.dataframe.samples.api.Modify#customConverters
- data has types
[Nothing?]
,kType
iskotlin.Int
- Seems to originate from
convertToImpl$convertToSchema
- data has types
org.jetbrains.kotlinx.dataframe.samples.api.Modify#implode
- data has types
[DataFrameImpl, Nothing?]
,kType
is:org.jetbrains.kotlinx.dataframe.DataFrame<*>
, not nullable - Seems to originate from
implodeImpl
where anull
is put in aFrameColumn
- data has types
org.jetbrains.kotlinx.dataframe.testSets.person.DataFrameTests#convertTo
- data has type:
[Nothing?]
,kType
is:kotlin.Int
- From
convertToImpl$convertToSchema
too
- data has type:
org.jetbrains.kotlinx.dataframe.testSets.person.DataFrameTreeTests#merge rows into table
- data has types
[DataFrameImpl, Nothing?]
,kType
is:org.jetbrains.kotlinx.dataframe.DataFrame<*>
, not nullable - Seems to originate from
implodeImpl
too where anull
is put in aFrameColumn
- data has types
Edit: running it afresh (clean pull of master with check) I get 15 failing tests.
There is also an exception in :dataframe-jdbc
: #701