Skip to content

Commit 3745aa9

Browse files
committed
made it so that nested types in jupyter codegen follow their parent's openness
1 parent 5f5f6a1 commit 3745aa9

File tree

4 files changed

+42
-9
lines changed

4 files changed

+42
-9
lines changed

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

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ internal class SchemaProcessorImpl(
5858
private fun generateFields(
5959
schema: DataFrameSchema,
6060
visibility: MarkerVisibility,
61+
openNestedDataSchemas: Boolean,
6162
requiredSuperMarkers: List<Marker> = emptyList(),
6263
): List<GeneratedField> {
6364
val usedFieldNames =
@@ -66,18 +67,26 @@ internal class SchemaProcessorImpl(
6667
fun getFieldType(columnSchema: ColumnSchema): FieldType =
6768
when (columnSchema) {
6869
is ColumnSchema.Value ->
69-
FieldType.ValueFieldType(columnSchema.type.toString())
70+
FieldType.ValueFieldType(typeFqName = columnSchema.type.toString())
7071

7172
is ColumnSchema.Group ->
7273
FieldType.GroupFieldType(
73-
process(columnSchema.schema, false, visibility).name,
74+
markerName = process(
75+
schema = columnSchema.schema,
76+
isOpen = openNestedDataSchemas,
77+
visibility = visibility,
78+
).name,
7479
renderAsObject = true,
7580
)
7681

7782
is ColumnSchema.Frame ->
7883
FieldType.FrameFieldType(
79-
process(columnSchema.schema, false, visibility).name,
80-
columnSchema.nullable,
84+
markerName = process(
85+
schema = columnSchema.schema,
86+
isOpen = openNestedDataSchemas,
87+
visibility = visibility,
88+
).name,
89+
nullable = columnSchema.nullable,
8190
renderAsList = true,
8291
)
8392

@@ -145,11 +154,24 @@ internal class SchemaProcessorImpl(
145154
}
146155
}
147156
}
148-
generateFields(scheme, visibility, baseMarkers)
157+
generateFields(
158+
schema = scheme,
159+
visibility = visibility,
160+
openNestedDataSchemas = isOpen,
161+
requiredSuperMarkers = baseMarkers,
162+
)
149163
} else {
150-
generateFields(scheme, visibility)
164+
generateFields(schema = scheme, visibility = visibility, openNestedDataSchemas = isOpen)
151165
}
152-
return Marker(name, isOpen, fields, baseMarkers.onlyLeafs(), visibility, emptyList(), emptyList())
166+
return Marker(
167+
name = name,
168+
isOpen = isOpen,
169+
fields = fields,
170+
superMarkers = baseMarkers.onlyLeafs(),
171+
visibility = visibility,
172+
typeParameters = emptyList(),
173+
typeArguments = emptyList(),
174+
)
153175
}
154176

155177
private fun DataFrameSchema.getRequiredMarkers() = registeredMarkers.filterRequiredForSchema(this)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class CodeGenerationTests : BaseTest() {
158158
val type2 = ReplCodeGeneratorImpl.markerInterfacePrefix
159159
val declaration1 =
160160
"""
161-
@DataSchema(isOpen = false)
161+
@DataSchema
162162
interface $type1 {
163163
val city: String?
164164
val name: String

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ class ReplCodeGenTests : BaseTest() {
277277
val c = repl.process(Test5.df, Test5::df)
278278
c.declarations shouldBe
279279
"""
280-
@DataSchema(isOpen = false)
280+
@DataSchema
281281
interface _DataFrameType3 {
282282
val a: Int
283283
val c: Int

dataframe-jupyter/src/test/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/CodeGenerationTests.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,15 @@ class CodeGenerationTests : DataFrameJupyterTest() {
7070
df1.leaf.c
7171
""".checkCompilation()
7272
}
73+
74+
// https://github.com/Kotlin/dataframe/issues/1222
75+
@Test
76+
fun `reusing marker with nullable column`() {
77+
@Language("kt")
78+
val _1 = """
79+
val df1 = dataFrameOf("group" to columnOf("a" to columnOf(1, null, 3)))
80+
val df2 = dataFrameOf("group" to columnOf("a" to columnOf(1, 2, 3)))
81+
df2.group.a
82+
""".checkCompilation()
83+
}
7384
}

0 commit comments

Comments
 (0)