Skip to content

Commit 3396425

Browse files
committed
fixing repl tests by allowing isMutable to be set even when dataframe is not bound to an actual property. Also non isOpen DataSchemas are no longer expected to be inherited from.
1 parent dff1e5d commit 3396425

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenerator.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ import org.jetbrains.kotlinx.dataframe.codeGen.CodeWithConverter
66
import org.jetbrains.kotlinx.dataframe.impl.codeGen.ReplCodeGeneratorImpl
77
import org.jetbrains.kotlinx.jupyter.api.Code
88
import kotlin.reflect.KClass
9+
import kotlin.reflect.KMutableProperty
910
import kotlin.reflect.KProperty
1011

1112
internal interface ReplCodeGenerator {
1213

13-
fun process(df: AnyFrame, property: KProperty<*>? = null): CodeWithConverter
14+
fun process(
15+
df: AnyFrame,
16+
property: KProperty<*>? = null,
17+
isMutable: Boolean = property is KMutableProperty?,
18+
): CodeWithConverter
1419

15-
fun process(row: AnyRow, property: KProperty<*>? = null): CodeWithConverter
20+
fun process(
21+
row: AnyRow,
22+
property: KProperty<*>? = null,
23+
isMutable: Boolean = property is KMutableProperty?,
24+
): CodeWithConverter
1625

1726
fun process(markerClass: KClass<*>): Code
1827

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/codeGen/ReplCodeGeneratorImpl.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import kotlin.reflect.KClass
1919
import kotlin.reflect.KMutableProperty
2020
import kotlin.reflect.KProperty
2121
import kotlin.reflect.KType
22+
import kotlin.reflect.KVisibility
2223
import kotlin.reflect.full.findAnnotation
2324
import kotlin.reflect.full.superclasses
2425
import kotlin.reflect.jvm.jvmErasure
@@ -44,11 +45,12 @@ internal class ReplCodeGeneratorImpl : ReplCodeGenerator {
4445
else -> null
4546
}
4647

47-
override fun process(row: AnyRow, property: KProperty<*>?) = process(row.df(), property)
48+
override fun process(row: AnyRow, property: KProperty<*>?, isMutable: Boolean) =
49+
process(row.df(), property, isMutable)
4850

49-
override fun process(df: AnyFrame, property: KProperty<*>?): CodeWithConverter {
51+
override fun process(df: AnyFrame, property: KProperty<*>?, isMutable: Boolean): CodeWithConverter {
5052
var targetSchema = df.schema()
51-
var isMutable = false
53+
var isMutable = isMutable
5254

5355
if (property != null) {
5456
val wasProcessedBefore = property in registeredProperties
@@ -77,7 +79,7 @@ internal class ReplCodeGeneratorImpl : ReplCodeGenerator {
7779
}
7880
}
7981

80-
return generate(targetSchema, markerInterfacePrefix, isMutable)
82+
return generate(schema = targetSchema, name = markerInterfacePrefix, isOpen = isMutable)
8183
}
8284

8385
fun generate(
@@ -92,7 +94,9 @@ internal class ReplCodeGeneratorImpl : ReplCodeGenerator {
9294
extensionProperties = true,
9395
isOpen = isOpen,
9496
visibility = MarkerVisibility.IMPLICIT_PUBLIC,
95-
knownMarkers = registeredMarkers.values,
97+
knownMarkers = registeredMarkers
98+
.filterKeys { it.visibility != KVisibility.PRIVATE }
99+
.values,
96100
)
97101

98102
result.newMarkers.forEach {

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/codeGen/ReplCodeGenTests.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ReplCodeGenTests : BaseTest() {
2626
val stringName = String::class.simpleName!!
2727

2828
class Test1 {
29-
@DataSchema(isOpen = false)
29+
@DataSchema
3030
interface _DataFrameType
3131

3232
@DataSchema(isOpen = false)
@@ -37,10 +37,10 @@ class ReplCodeGenTests : BaseTest() {
3737
}
3838

3939
class Test2 {
40-
@DataSchema(isOpen = false)
40+
@DataSchema
4141
interface _DataFrameType
4242

43-
@DataSchema(isOpen = false)
43+
@DataSchema
4444
interface _DataFrameType1
4545

4646
@DataSchema(isOpen = false)
@@ -68,13 +68,13 @@ class ReplCodeGenTests : BaseTest() {
6868
@Test
6969
fun `process derived markers`() {
7070
val repl = ReplCodeGenerator.create()
71-
val code = repl.process(df).declarations
71+
val code = repl.process(df, isMutable = true).declarations
7272

7373
val marker = ReplCodeGeneratorImpl.markerInterfacePrefix
7474
val markerFull = Test1._DataFrameType::class.qualifiedName!!
7575

7676
val expected = """
77-
@DataSchema(isOpen = false)
77+
@DataSchema
7878
interface $marker
7979
8080
val $dfName<$marker>.age: $dataCol<$intName> @JvmName("${marker}_age") get() = this["age"] as $dataCol<$intName>
@@ -100,7 +100,7 @@ class ReplCodeGenTests : BaseTest() {
100100
code2 shouldBe ""
101101

102102
val df3 = typed.filter { city != null }
103-
val code3 = repl.process(df3).declarations
103+
val code3 = repl.process(df3, isMutable = false).declarations
104104
val marker3 = marker + "1"
105105
val expected3 = """
106106
@DataSchema(isOpen = false)
@@ -118,7 +118,7 @@ class ReplCodeGenTests : BaseTest() {
118118
code4 shouldBe ""
119119

120120
val df5 = typed.filter { weight != null }
121-
val code5 = repl.process(df5).declarations
121+
val code5 = repl.process(df5, isMutable = false).declarations
122122
val marker5 = marker + "2"
123123
val expected5 = """
124124
@DataSchema(isOpen = false)
@@ -149,7 +149,7 @@ class ReplCodeGenTests : BaseTest() {
149149
150150
""".trimIndent()
151151

152-
val code = repl.process(typed).declarations.trimIndent()
152+
val code = repl.process(typed, isMutable = false).declarations.trimIndent()
153153
code shouldBe expected
154154
}
155155

@@ -176,7 +176,7 @@ class ReplCodeGenTests : BaseTest() {
176176
val $dfRowName<$marker?>.weight: $intName? @JvmName("Nullable${marker}_weight") get() = this["weight"] as $intName?
177177
""".trimIndent()
178178

179-
val code = repl.process(typed).declarations.trimIndent()
179+
val code = repl.process(typed, isMutable = false).declarations.trimIndent()
180180
code shouldBe expected
181181
}
182182

0 commit comments

Comments
 (0)