Skip to content

Commit

Permalink
Fix #640: Jupyter integration conflicts with variable type converters…
Browse files Browse the repository at this point in the history
… from other integrations.
  • Loading branch information
ark-1 committed Apr 2, 2024
1 parent 35792c9 commit 790d889
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,20 @@ internal class Integration(
import("org.jetbrains.kotlinx.dataframe.dataTypes.*")
import("org.jetbrains.kotlinx.dataframe.impl.codeGen.urlCodeGenReader")

updateVariable<Any> { instance, property ->
when (instance) {
is AnyCol -> updateAnyColVariable(instance, property, codeGen)
is ColumnGroup<*> -> updateColumnGroupVariable(instance, property, codeGen)
is AnyRow -> updateAnyRowVariable(instance, property, codeGen)
is AnyFrame -> updateAnyFrameVariable(instance, property, codeGen)
is ImportDataSchema -> updateImportDataSchemaVariable(instance, property)
else -> null
}
updateVariableByRuntimeType<AnyCol> { instance, property ->
updateAnyColVariable(instance, property, codeGen)
}
updateVariableByRuntimeType<ColumnGroup<*>> { instance, property ->
updateColumnGroupVariable(instance, property, codeGen)
}
updateVariableByRuntimeType<AnyRow> { instance, property ->
updateAnyRowVariable(instance, property, codeGen)
}
updateVariableByRuntimeType<AnyFrame> { instance, property ->
updateAnyFrameVariable(instance, property, codeGen)
}
updateVariableByRuntimeType<ImportDataSchema> { instance, property ->
updateImportDataSchemaVariable(instance, property)
}

fun KotlinKernelHost.addDataSchemas(classes: List<KClass<*>>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,23 @@ class JupyterCodegenTests : JupyterReplTestCase() {
res2.shouldBeInstanceOf<Unit>()
}

@Test
fun `type converter does not conflict with other type converters`() {
@Language("kts")
val anotherTypeConverter = """
notebook.fieldsHandlersProcessor.register(
FieldHandlerFactory.createUpdateHandler<ByteArray>(TypeDetection.RUNTIME) { _, prop ->
execute(prop.name + ".toList()").name
},
ProcessingPriority.LOW
)
""".trimIndent()
execEx(anotherTypeConverter)
execEx("val x = ByteArray(1)")
val res1 = execRaw("x")
res1.shouldBeInstanceOf<List<*>>()
}

@Test
fun `generate a new marker when dataframe marker is not a data schema so that columns are accessible with extensions`() {
@Language("kts")
Expand Down

0 comments on commit 790d889

Please sign in to comment.