Skip to content

Commit e3ddfcf

Browse files
Automated commit of generated code
1 parent aea1e14 commit e3ddfcf

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/columns/DataColumnImpl.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package org.jetbrains.kotlinx.dataframe.impl.columns
22

3+
import org.jetbrains.kotlinx.dataframe.BuildConfig
34
import org.jetbrains.kotlinx.dataframe.DataColumn
45
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
6+
import org.jetbrains.kotlinx.dataframe.impl.isArray
7+
import org.jetbrains.kotlinx.dataframe.impl.isPrimitiveArray
8+
import kotlin.reflect.KClass
59
import kotlin.reflect.KType
10+
import kotlin.reflect.full.isSubclassOf
611

712
internal abstract class DataColumnImpl<T>(
813
protected val values: List<T>,
@@ -12,6 +17,31 @@ internal abstract class DataColumnImpl<T>(
1217
) : DataColumn<T>,
1318
DataColumnInternal<T> {
1419

20+
private infix fun <T> T?.matches(type: KType) =
21+
when {
22+
this == null -> type.isMarkedNullable
23+
24+
this.isPrimitiveArray ->
25+
type.isPrimitiveArray &&
26+
this!!::class.qualifiedName == type.classifier?.let { (it as KClass<*>).qualifiedName }
27+
28+
this.isArray -> type.isArray
29+
30+
// cannot check the precise type of array
31+
else -> this!!::class.isSubclassOf(type.classifier as KClass<*>)
32+
}
33+
34+
init {
35+
// Check for [Issue #713](https://github.com/Kotlin/dataframe/issues/713).
36+
// This only runs with `kotlin.dataframe.debug=true` in gradle.properties.
37+
if (BuildConfig.DEBUG) {
38+
require(values.all { it matches type }) {
39+
val types = values.map { if (it == null) "Nothing?" else it!!::class.simpleName }.distinct()
40+
"Values of column '$name' have types '$types' which are not compatible given with column type '$type'"
41+
}
42+
}
43+
}
44+
1545
protected val distinct = distinct ?: lazy { values.toSet() }
1646

1747
override fun name() = name
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package org.jetbrains.kotlinx.dataframe.jupyter
22

3+
import org.jetbrains.kotlinx.dataframe.BuildConfig
34
import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration
45

56
public class JupyterConfiguration {
67
public val display: DisplayConfiguration = DisplayConfiguration()
78

9+
/** Version of the library. */
10+
public val version: String = BuildConfig.VERSION
11+
812
/** DSL accessor. */
913
public operator fun invoke(block: JupyterConfiguration.() -> Unit): JupyterConfiguration = apply(block)
1014
}

0 commit comments

Comments
 (0)