Skip to content

Commit c16b37e

Browse files
committed
adds kotlin.dataframe.debug property which runs the #713 checks when enabled. Updated contribution guide too. TC will have to be updated manually
1 parent 9bacc4e commit c16b37e

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

Diff for: CONTRIBUTING.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ so do familiarize yourself with the following guidelines.
5252

5353
## PR workflow
5454

55-
0. The contributor builds the library locally and runs all unit tests via the Gradle task `dataframe:test`
56-
(see the ["Building"](#building) chapter).
55+
0. The contributor builds the library locally and runs all unit tests via the Gradle task
56+
`dataframe:test -Pkotlin.dataframe.debug=true` (see the ["Building"](#building) chapter).
5757
1. The contributor submits the PR if the local build is successful and the tests are green.
5858
2. The reviewer puts their name in the "Reviewers" section of the proposed PR at the start of the review process.
5959
3. The reviewer leaves comments or marks the PR with the abbreviation "LGTM" (Looks good to me).
@@ -103,6 +103,8 @@ This library is built with Gradle.
103103
* Run `./gradlew build` to build. It also runs all the tests and checks the linter.
104104
* Run `./gradlew <module>:test` to test the module you are looking at to speed
105105
things up during development.
106+
* Make sure to pass the extra parameter `-Pkotlin.dataframe.debug=true` to enable debug mode. This flag will
107+
make sure some extra checks are run, which are important but too heavy for production.
106108

107109
You can import this project into IDEA, but you have to delegate the build actions
108110
to Gradle (in Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> Runner)

Diff for: build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ allprojects {
163163
packageName = "org.jetbrains.kotlinx.dataframe"
164164
className = "BuildConfig"
165165
buildConfigField("VERSION", "${project.version}")
166+
buildConfigField("DEBUG", findProperty("kotlin.dataframe.debug")?.toString()?.toBoolean() ?: false)
166167
}
167168
} catch (_: UnknownDomainObjectException) {
168169
logger.warn("Could not set buildConfig on :${this.name}")

Diff for: core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/columns/DataColumnImpl.kt

+31
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,32 @@ 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+
*/
38+
if (BuildConfig.DEBUG) {
39+
require(values.all { it matches type }) {
40+
val types = values.map { if (it == null) "Nothing?" else it!!::class.simpleName }.distinct()
41+
"Values of column '$name' have types '$types' which are not compatible given with column type '$type'"
42+
}
43+
}
44+
}
45+
1546
protected val distinct = distinct ?: lazy { values.toSet() }
1647

1748
override fun name() = name

Diff for: gradle.properties

+5
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ org.gradle.jvmargs=-Xmx4G
1111
# This makes it mandatory to explicitly apply your own version of the
1212
# KSP plugin in the modules that use it.
1313
kotlin.dataframe.add.ksp=false
14+
15+
# Enables debug mode for dataframe.
16+
# This can make certain tests run that should not be run in production.
17+
# It can also be turned on from the command line with `-Pkotlin.dataframe.debug=true`
18+
kotlin.dataframe.debug=false

0 commit comments

Comments
 (0)