File tree Expand file tree Collapse file tree 4 files changed +70
-6
lines changed
main/kotlin/org/jetbrains/kotlinx/dataframe
test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter Expand file tree Collapse file tree 4 files changed +70
-6
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,10 @@ internal object MarkersExtractor {
37
37
fun get (markerClass : KClass <* >, nullableProperties : Boolean = false): Marker =
38
38
cache.getOrPut(Pair (markerClass, nullableProperties)) {
39
39
val fields = getFields(markerClass, nullableProperties)
40
- val isOpen = markerClass.findAnnotation<DataSchema >()?.isOpen ? : false
40
+ val isOpen = ! markerClass.isSealed &&
41
+ markerClass.java.isInterface &&
42
+ markerClass.findAnnotation<DataSchema >()?.isOpen == true
43
+
41
44
val baseSchemas = markerClass.superclasses.filter { it != Any ::class }.map { get(it, nullableProperties) }
42
45
Marker (
43
46
name = markerClass.qualifiedName ? : markerClass.simpleName!! ,
Original file line number Diff line number Diff line change @@ -92,9 +92,7 @@ internal class ReplCodeGeneratorImpl : ReplCodeGenerator {
92
92
extensionProperties = true ,
93
93
isOpen = isOpen,
94
94
visibility = MarkerVisibility .IMPLICIT_PUBLIC ,
95
- knownMarkers = registeredMarkers
96
- .filterKeys { ! it.isData } // filter out data classes, so they aren't used as supertypes
97
- .values,
95
+ knownMarkers = registeredMarkers.values,
98
96
)
99
97
100
98
result.newMarkers.forEach {
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ internal class SchemaProcessorImpl(
22
22
override val generatedMarkers = mutableListOf<Marker >()
23
23
24
24
private fun DataFrameSchema.getAllSuperMarkers () = registeredMarkers
25
- .filter { it.schema.compare(this ).isSuperOrEqual() }
25
+ .filter { it.isOpen && it. schema.compare(this ).isSuperOrEqual() }
26
26
27
27
private fun List<Marker>.onlyLeafs (): List <Marker > {
28
28
val skip = flatMap { it.allSuperMarkers.keys }.toSet()
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ class JupyterCodegenTests : JupyterReplTestCase() {
36
36
@Language(" kts" )
37
37
val res1 = exec(
38
38
"""
39
- @DataSchema(isOpen = false)
39
+ @DataSchema
40
40
data class A(val a: Int)
41
41
""" .trimIndent()
42
42
)
@@ -52,6 +52,69 @@ class JupyterCodegenTests : JupyterReplTestCase() {
52
52
(res2 as AnyFrame ).should { it.isNotEmpty() }
53
53
}
54
54
55
+ @Test
56
+ fun `Don't inherit from non open class` () {
57
+ @Language(" kts" )
58
+ val res1 = exec(
59
+ """
60
+ @DataSchema
61
+ class A(val a: Int)
62
+ """ .trimIndent()
63
+ )
64
+
65
+ @Language(" kts" )
66
+ val res2 = execRaw(
67
+ """
68
+ val df = dataFrameOf("a", "b")(1, 2)
69
+ df
70
+ """ .trimIndent()
71
+ )
72
+
73
+ (res2 as AnyFrame ).should { it.isNotEmpty() }
74
+ }
75
+
76
+ @Test
77
+ fun `Don't inherit from open class` () {
78
+ @Language(" kts" )
79
+ val res1 = exec(
80
+ """
81
+ @DataSchema
82
+ open class A(val a: Int)
83
+ """ .trimIndent()
84
+ )
85
+
86
+ @Language(" kts" )
87
+ val res2 = execRaw(
88
+ """
89
+ val df = dataFrameOf("a", "b")(1, 2)
90
+ df
91
+ """ .trimIndent()
92
+ )
93
+
94
+ (res2 as AnyFrame ).should { it.isNotEmpty() }
95
+ }
96
+
97
+ @Test
98
+ fun `Do inherit from open interface` () {
99
+ @Language(" kts" )
100
+ val res1 = exec(
101
+ """
102
+ @DataSchema
103
+ interface A { val a: Int }
104
+ """ .trimIndent()
105
+ )
106
+
107
+ @Language(" kts" )
108
+ val res2 = execRaw(
109
+ """
110
+ val df = dataFrameOf("a", "b")(1, 2)
111
+ df
112
+ """ .trimIndent()
113
+ )
114
+
115
+ (res2 as AnyFrame ).should { it.isNotEmpty() }
116
+ }
117
+
55
118
@Test
56
119
fun `codegen for enumerated frames` () {
57
120
@Language(" kts" )
You can’t perform that action at this time.
0 commit comments