diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/add.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/add.kt index ae5754dceb..aa70e00076 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/add.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/add.kt @@ -322,8 +322,10 @@ public class AddDsl( add(dsl.columns.toColumnGroup(name)) } + @Interpretable("AddDslAddGroup") public fun group(body: AddDsl.() -> Unit): AddGroup = AddGroup(body) + @Interpretable("AddDslAddGroupInto") public infix fun AddGroup.into(groupName: String): Unit = group(groupName, body) @Deprecated(DEPRECATED_ACCESS_API) diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt index 3752dccd4d..b532a29368 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt @@ -169,6 +169,10 @@ public interface TraversePropertiesDsl { public fun preserve(vararg properties: KCallable<*>) } +/** + * Store values of given type [T] in ValueColumns without transformation into ColumnGroups or FrameColumns. + */ +@Interpretable("PreserveT") public inline fun TraversePropertiesDsl.preserve(): Unit = preserve(T::class) public abstract class CreateDataFrameDsl : TraversePropertiesDsl { @@ -177,8 +181,10 @@ public abstract class CreateDataFrameDsl : TraversePropertiesDsl { public abstract fun add(column: AnyBaseCol, path: ColumnPath? = null) + @Interpretable("ToDataFrameDslIntoString") public infix fun AnyBaseCol.into(name: String): Unit = add(this, pathOf(name)) + @Interpretable("ToDataFrameDslIntoPath") public infix fun AnyBaseCol.into(path: ColumnPath): Unit = add(this, path) @Interpretable("Properties0") @@ -191,6 +197,7 @@ public abstract class CreateDataFrameDsl : TraversePropertiesDsl { public inline fun expr(infer: Infer = Infer.Nulls, noinline expression: (T) -> R): DataColumn = source.map { expression(it) }.toColumn(infer = infer) + @Interpretable("ToDataFrameDslAdd") public inline fun add(name: String, noinline expression: (T) -> R): Unit = add(source.map { expression(it) }.toColumn(name, Infer.Nulls)) @@ -202,6 +209,7 @@ public abstract class CreateDataFrameDsl : TraversePropertiesDsl { public inline infix fun KProperty.from(noinline expression: (T) -> R): Unit = add(columnName, expression) + @Interpretable("ToDataFrameDslFromInferType") public inline infix fun String.from(inferType: InferType): Unit = add(DataColumn.createByInference(this, source.map { inferType.expression(it) })) diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt index 79be7aeae3..c0e4d055bf 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt @@ -167,6 +167,25 @@ class CreateDataFrameTests { df2.a.kind() shouldBe ColumnKind.Group } + class ExcludeTestData(val s: String, val data: NestedData) + + class NestedData(val i: Int, val nestedStr: String) + + @Test + fun `preserve T test`() { + val data = listOf( + ExcludeTestData("test", NestedData(42, "nested")), + ExcludeTestData("test2", NestedData(43, "nested2")), + ) + + val res = data.toDataFrame { + preserve() + properties(maxDepth = 2) + } + + res.schema() shouldBe data.toDataFrame(maxDepth = 0).schema() + } + enum class DummyEnum { A } @Test