Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -1672,14 +1672,18 @@ public final class org/jetbrains/kotlinx/dataframe/api/CountKt {
public static synthetic fun count$default (Lorg/jetbrains/kotlinx/dataframe/api/Grouped;Ljava/lang/String;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/DataFrame;
}

public abstract class org/jetbrains/kotlinx/dataframe/api/CreateDataFrameDsl : org/jetbrains/kotlinx/dataframe/api/TraversePropertiesDsl {
public abstract class org/jetbrains/kotlinx/dataframe/api/CreateDataFrameDsl {
public fun <init> ()V
public abstract fun add (Lorg/jetbrains/kotlinx/dataframe/columns/BaseColumn;Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;)V
public static synthetic fun add$default (Lorg/jetbrains/kotlinx/dataframe/api/CreateDataFrameDsl;Lorg/jetbrains/kotlinx/dataframe/columns/BaseColumn;Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;ILjava/lang/Object;)V
public final fun exclude ([Lkotlin/reflect/KCallable;)V
public final fun exclude ([Lkotlin/reflect/KClass;)V
public abstract fun getSource ()Ljava/lang/Iterable;
public final fun into (Lorg/jetbrains/kotlinx/dataframe/columns/BaseColumn;Ljava/lang/String;)V
public final fun into (Lorg/jetbrains/kotlinx/dataframe/columns/BaseColumn;Lorg/jetbrains/kotlinx/dataframe/columns/ColumnPath;)V
public abstract fun invoke (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public final fun preserve ([Lkotlin/reflect/KCallable;)V
public final fun preserve ([Lkotlin/reflect/KClass;)V
public abstract fun properties ([Lkotlin/reflect/KCallable;ILkotlin/jvm/functions/Function1;)V
public static synthetic fun properties$default (Lorg/jetbrains/kotlinx/dataframe/api/CreateDataFrameDsl;[Lkotlin/reflect/KCallable;ILkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.jetbrains.kotlinx.dataframe.impl.columnName
import org.jetbrains.kotlinx.dataframe.impl.columns.createColumnGuessingType
import org.jetbrains.kotlinx.dataframe.index
import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
import org.jetbrains.kotlinx.dataframe.util.TRAVERSE_PROPERTIES_DSL
import kotlin.reflect.KCallable
import kotlin.reflect.KClass
import kotlin.reflect.KProperty
Expand Down Expand Up @@ -153,6 +154,24 @@ public fun Iterable<Pair<String, Iterable<Any?>>>.toDataFrameFromPairs(): DataFr
ColumnPath(it.first) to createColumnGuessingType(it.first, it.second.asList())
}.toDataFrameFromPairs<Unit>()

/**
* [DslMarker] to prevent fucntions from [CreateDataFrameDsl] being used inside [TraversePropertiesDsl].
* This prevents notations like:
* ```kt
* list.toDataFrame {
* "colA" from { ... }
* properties {
* preserve<T>()
* "colB" from { ... } // ERROR, cannot be called in this context an implicit receiver.
* }
* }
* ```
*/
@DslMarker
@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS, AnnotationTarget.TYPE, AnnotationTarget.FUNCTION)
public annotation class CreateDataFrameDslMarker

@CreateDataFrameDslMarker
public interface TraversePropertiesDsl {

/**
Expand Down Expand Up @@ -188,7 +207,11 @@ public interface TraversePropertiesDsl {
@Interpretable("PreserveT")
public inline fun <reified T> TraversePropertiesDsl.preserve(): Unit = preserve(T::class)

public abstract class CreateDataFrameDsl<T> : TraversePropertiesDsl {
@Deprecated(TRAVERSE_PROPERTIES_DSL, level = DeprecationLevel.ERROR)
public inline fun <reified T> CreateDataFrameDsl<*>.preserve(): Unit = Unit

@CreateDataFrameDslMarker
public abstract class CreateDataFrameDsl<T> {

public abstract val source: Iterable<T>

Expand All @@ -207,6 +230,18 @@ public abstract class CreateDataFrameDsl<T> : TraversePropertiesDsl {
body: (TraversePropertiesDsl.() -> Unit)? = null,
)

@Deprecated(TRAVERSE_PROPERTIES_DSL, level = DeprecationLevel.ERROR)
public fun exclude(vararg classes: KClass<*>): Unit = Unit

@Deprecated(TRAVERSE_PROPERTIES_DSL, level = DeprecationLevel.ERROR)
public fun exclude(vararg properties: KCallable<*>): Unit = Unit

@Deprecated(TRAVERSE_PROPERTIES_DSL, level = DeprecationLevel.ERROR)
public fun preserve(vararg classes: KClass<*>): Unit = Unit

@Deprecated(TRAVERSE_PROPERTIES_DSL, level = DeprecationLevel.ERROR)
public fun preserve(vararg properties: KCallable<*>): Unit = Unit

public inline fun <reified R> expr(infer: Infer = Infer.Nulls, noinline expression: (T) -> R): DataColumn<R> =
source.map { expression(it) }.toColumn(infer = infer)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ internal class CreateDataFrameDslImpl<T>(
private val type: KType,
private val prefix: ColumnPath = emptyPath(),
private val configuration: TraverseConfiguration = TraverseConfiguration(),
) : CreateDataFrameDsl<T>(),
TraversePropertiesDsl by configuration {
) : CreateDataFrameDsl<T>() {

internal val columns = mutableListOf<Pair<ColumnPath, AnyBaseCol>>()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ internal const val DATAROW_READ =
internal const val SUPPORTED_DATAFRAME_FORMAT: String =
"SupportedDataFrameFormat is deprecated. $MESSAGE_1_0"

internal const val TRAVERSE_PROPERTIES_DSL =
"Top-level `exclude`/`preserve` calls in `toDataFrame {}` are deprecated. " +
"Move them into each `properties { }` block to configure traversal instead. $MESSAGE_1_0"

// endregion

// region WARNING in 1.0, ERROR in 1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ class CreateDataFrameTests {
)

val res = data.toDataFrame {
preserve<NestedData>()
properties(maxDepth = 2)
properties(maxDepth = 2) {
preserve<NestedData>()
}
}

res.schema() shouldBe data.toDataFrame(maxDepth = 0).schema()
Expand Down
Loading