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
48 changes: 34 additions & 14 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -2739,17 +2739,6 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/api/KeyValueProp
public abstract fun getValue ()Ljava/lang/Object;
}

public final class org/jetbrains/kotlinx/dataframe/api/KeyValueProperty_ExtensionsKt {
public static final fun KeyValueProperty_key (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun KeyValueProperty_key (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
public static final fun KeyValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun KeyValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Object;
public static final fun NullableKeyValueProperty_key (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NullableKeyValueProperty_key (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
public static final fun NullableKeyValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NullableKeyValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Object;
}

public abstract interface class org/jetbrains/kotlinx/dataframe/api/LastColumnsSelectionDsl {
public fun last (Lorg/jetbrains/kotlinx/dataframe/api/ColumnsSelectionDsl;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;
public fun last (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnSet;Lkotlin/jvm/functions/Function1;)Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;
Expand Down Expand Up @@ -3466,15 +3455,15 @@ public final class org/jetbrains/kotlinx/dataframe/api/MoveKt {
public static final fun under (Lorg/jetbrains/kotlinx/dataframe/api/MoveClause;Lorg/jetbrains/kotlinx/dataframe/columns/ColumnAccessor;)Lorg/jetbrains/kotlinx/dataframe/DataFrame;
}

public final class org/jetbrains/kotlinx/dataframe/api/NameValuePair {
public final class org/jetbrains/kotlinx/dataframe/api/NameValuePair : org/jetbrains/kotlinx/dataframe/api/NameValueProperty {
public fun <init> (Ljava/lang/String;Ljava/lang/Object;)V
public final fun component1 ()Ljava/lang/String;
public final fun component2 ()Ljava/lang/Object;
public final fun copy (Ljava/lang/String;Ljava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/api/NameValuePair;
public static synthetic fun copy$default (Lorg/jetbrains/kotlinx/dataframe/api/NameValuePair;Ljava/lang/String;Ljava/lang/Object;ILjava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/api/NameValuePair;
public fun equals (Ljava/lang/Object;)Z
public final fun getName ()Ljava/lang/String;
public final fun getValue ()Ljava/lang/Object;
public fun getName ()Ljava/lang/String;
public fun getValue ()Ljava/lang/Object;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}
Expand All @@ -3490,6 +3479,37 @@ public final class org/jetbrains/kotlinx/dataframe/api/NameValuePair_ExtensionsK
public static final fun NullableNameValuePair_value (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Object;
}

public abstract interface class org/jetbrains/kotlinx/dataframe/api/NameValueProperty {
public abstract fun getName ()Ljava/lang/String;
public abstract fun getValue ()Ljava/lang/Object;
}

public final class org/jetbrains/kotlinx/dataframe/api/NameValuePropertyKt {
public static final fun KeyValueProperty_key (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun KeyValueProperty_key (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
public static final fun KeyValueProperty_name (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun KeyValueProperty_name (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
public static final fun KeyValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun KeyValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Object;
public static final fun NullableKeyValueProperty_key (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NullableKeyValueProperty_key (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
public static final fun NullableKeyValueProperty_name (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NullableKeyValueProperty_name (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
public static final fun NullableKeyValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NullableKeyValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Object;
}

public final class org/jetbrains/kotlinx/dataframe/api/NameValueProperty_ExtensionsKt {
public static final fun NameValueProperty_name (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NameValueProperty_name (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
public static final fun NameValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NameValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Object;
public static final fun NullableNameValueProperty_name (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NullableNameValueProperty_name (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
public static final fun NullableNameValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
public static final fun NullableNameValueProperty_value (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Object;
}

public abstract interface class org/jetbrains/kotlinx/dataframe/api/NoneColumnsSelectionDsl {
public fun none ()Lorg/jetbrains/kotlinx/dataframe/columns/ColumnsResolver;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.jetbrains.kotlinx.dataframe.annotations

import org.jetbrains.kotlinx.dataframe.api.JsonPath
import org.jetbrains.kotlinx.dataframe.api.KeyValueProperty
import org.jetbrains.kotlinx.dataframe.api.NameValueProperty
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
import org.jetbrains.kotlinx.dataframe.documentation.UnifyingNumbers
Expand Down Expand Up @@ -78,7 +78,7 @@ public annotation class JsonOptions(
* */
public val typeClashTactic: String = TypeClashTactics.ARRAY_AND_VALUE_COLUMNS,
/**
* List of [JsonPath]s where instead of a [ColumnGroup], a [FrameColumn]<[KeyValueProperty]>
* List of [JsonPath]s where instead of a [ColumnGroup], a [FrameColumn]<[NameValueProperty]>
* will be created.
*
* Example:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public inline fun <reified R> AnyRow.valuesOf(): List<R> = values().filterIsInst
// region DataSchema
@DataSchema
@RequiredByIntellijPlugin
public data class NameValuePair<V>(val name: String, val value: V)
public data class NameValuePair<V>(override val name: String, override val value: V) : NameValueProperty<V>

// Without these overloads row.transpose().name or row.map { name } won't resolve
public val ColumnsContainer<NameValuePair<*>>.name: DataColumn<String>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
@file:Suppress("UNCHECKED_CAST", "DEPRECATION")

package org.jetbrains.kotlinx.dataframe.api

import org.jetbrains.kotlinx.dataframe.ColumnsScope
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.annotations.ColumnName
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
import org.jetbrains.kotlinx.dataframe.util.KEY_VALUE_PROPERTY
import org.jetbrains.kotlinx.dataframe.util.KEY_VALUE_PROPERTY_KEY

/** A [DataSchema] interface / class can implement this if it represents a map-like data schema (so name: value). */
@DataSchema
public interface NameValueProperty<T> {
// needs to be explicitly overridden in @DataSchema interface, otherwise extension functions won't generate (TODO)
public val name: String

// needs to be explicitly overridden in @DataSchema interface, otherwise type will be read as `T` and extensions won't generate (TODO)
@ColumnName("value")
public val `value`: T
}

// region Deprecated

/** A [DataSchema] interface / class can implement this if it represents a map-like data schema (so key: value). */
@Deprecated(KEY_VALUE_PROPERTY, ReplaceWith("NameValueProperty<T>"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is it working as expected? Never tried replace with + generics

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image image yep :)

public interface KeyValueProperty<T> {
// needs to be explicitly overridden in @DataSchema interface, otherwise extension functions won't generate (TODO)
public val key: String

// needs to be explicitly overridden in @DataSchema interface, otherwise type will be read as `T` and extensions won't generate (TODO)
@ColumnName("value")
public val `value`: T
}

@Deprecated(KEY_VALUE_PROPERTY_KEY, ReplaceWith("name"))
public val ColumnsScope<KeyValueProperty<*>>.key: DataColumn<String>
@JvmName("KeyValueProperty_key")
get() = this["key"].cast()

@Deprecated(KEY_VALUE_PROPERTY_KEY, ReplaceWith("name"))
public val ColumnsScope<KeyValueProperty<*>?>.key: DataColumn<String?>
@JvmName("NullableKeyValueProperty_key")
get() = this["key"].cast()

@Deprecated(KEY_VALUE_PROPERTY_KEY, ReplaceWith("name"))
public val DataRow<KeyValueProperty<*>>.key: String
@JvmName("KeyValueProperty_key")
get() = this["key"] as String

@Deprecated(KEY_VALUE_PROPERTY_KEY, ReplaceWith("name"))
public val DataRow<KeyValueProperty<*>?>.key: String?
@JvmName("NullableKeyValueProperty_key")
get() = this["key"] as String?

/**
* Accesses the 'key' column of this [KeyValueProperty][KeyValueProperty]
* [ColumnsContainer][org.jetbrains.kotlinx.dataframe.ColumnsContainer].
*
* This is a temporary, future-proof, extension property in preparation of the migration from [KeyValueProperty]
* to [NameValueProperty].
*/
public val ColumnsScope<KeyValueProperty<*>>.name: DataColumn<String>
@JvmName("KeyValueProperty_name")
get() = key

/**
* Accesses the 'key' column of this [KeyValueProperty][KeyValueProperty]
* [ColumnsContainer][org.jetbrains.kotlinx.dataframe.ColumnsContainer].
*
* This is a temporary, future-proof, extension property in preparation of the migration from [KeyValueProperty]
* to [NameValueProperty].
*/
public val ColumnsScope<KeyValueProperty<*>?>.name: DataColumn<String?>
@JvmName("NullableKeyValueProperty_name")
get() = key

/**
* Accesses the 'key' value of this [KeyValueProperty][KeyValueProperty]
* [DataRow][DataRow].
*
* This is a temporary, future-proof, extension property in preparation of the migration from [KeyValueProperty]
* to [NameValueProperty].
*/
public val DataRow<KeyValueProperty<*>>.name: String
@JvmName("KeyValueProperty_name")
get() = key

/**
* Accesses the 'key' value of this [KeyValueProperty][KeyValueProperty]
* [DataRow][DataRow].
*
* This is a temporary, future-proof, extension property in preparation of the migration from [KeyValueProperty]
* to [NameValueProperty].
*/
public val DataRow<KeyValueProperty<*>?>.name: String?
@JvmName("NullableKeyValueProperty_name")
get() = key

public val <T : Any?> ColumnsScope<KeyValueProperty<T>>.value: DataColumn<T>
@JvmName("KeyValueProperty_value")
get() = this["value"].cast()

public val <T : Any?> ColumnsScope<KeyValueProperty<T>?>.value: DataColumn<T?>
@JvmName("NullableKeyValueProperty_value")
get() = this["value"].cast()

public val <T : Any?> DataRow<KeyValueProperty<T>>.value: T
@JvmName("KeyValueProperty_value")
get() = this["value"] as T

public val <T : Any?> DataRow<KeyValueProperty<T>?>.value: T?
@JvmName("NullableKeyValueProperty_value")
get() = this["value"] as T?

// endregion
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ internal const val COPY_REPLACE = "columns().toDataFrame().cast()"
internal const val LISTS_TO_DATAFRAME_MIGRATION =
"Function moved from io to api package, and a new `header` parameter is introduced. $MESSAGE_1_1"

internal const val KEY_VALUE_PROPERTY = "Deprecated in favor of NameValueProperty. $MESSAGE_1_1"
internal const val KEY_VALUE_PROPERTY_KEY =
"This column will be renamed to 'name' when KeyValueProperty will be replaced with NameValueProperty. $MESSAGE_1_1"

// endregion

// region keep across releases
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.api.JsonPath
import org.jetbrains.kotlinx.dataframe.api.KeyValueProperty
import org.jetbrains.kotlinx.dataframe.api.NameValueProperty
import org.jetbrains.kotlinx.dataframe.api.cast
import org.jetbrains.kotlinx.dataframe.api.chunked
import org.jetbrains.kotlinx.dataframe.api.columnOf
Expand Down Expand Up @@ -67,7 +67,7 @@ private enum class AnyColType {
OBJECTS,
}

internal interface AnyKeyValueProperty : KeyValueProperty<Any?> {
internal interface AnyNameValueProperty : NameValueProperty<Any?> {
override val value: Any?
}

Expand Down Expand Up @@ -122,7 +122,7 @@ internal fun readJsonImpl(
*
* @param records List of json elements to be converted to a [DataFrame].
* @param unifyNumbers Whether to [unify the numbers that are read][UnifyingNumbers].
* @param keyValuePaths List of [JsonPath]s where instead of a [ColumnGroup], a [FrameColumn]<[KeyValueProperty]>
* @param keyValuePaths List of [JsonPath]s where instead of a [ColumnGroup], a [FrameColumn]<[NameValueProperty]>
* will be created.
* @param header Optional list of column names. If given, [records] will be read like an object with [header] being the keys.
* @return [DataFrame] from the given [records].
Expand Down Expand Up @@ -340,22 +340,22 @@ internal fun fromJsonListAnyColumns(
valueTypes += valueType

dataFrameOf(
columnOf(*map.keys.toTypedArray()).named(KeyValueProperty<*>::key.name),
columnOf(*map.keys.toTypedArray()).named(NameValueProperty<*>::name.name),
createColumnGuessingType(
values = map.values,
suggestedType = TypeSuggestion.Use(valueType),
unifyNumbers = unifyNumbers,
).named(KeyValueProperty<*>::value.name),
).named(NameValueProperty<*>::value.name),
)
}

is JsonNull, null -> DataFrame.emptyOf<AnyKeyValueProperty>()
is JsonNull, null -> DataFrame.emptyOf<AnyNameValueProperty>()

else -> error("Expected JsonObject, got $record")
}
}

val valueColumns = dataFrames.map { it[KeyValueProperty<*>::value.name] }
val valueColumns = dataFrames.map { it[NameValueProperty<*>::value.name] }
val valueColumnSchema = when {
// in these cases we can safely combine the columns to get a single column schema
valueColumns.all { it is ColumnGroup<*> } || valueColumns.all { it is FrameColumn<*> } ->
Expand All @@ -373,8 +373,8 @@ internal fun fromJsonListAnyColumns(
schema = lazy {
DataFrameSchemaImpl(
columns = mapOf(
KeyValueProperty<*>::key.name to ColumnSchema.Value(typeOf<String>()),
KeyValueProperty<*>::value.name to valueColumnSchema,
NameValueProperty<*>::name.name to ColumnSchema.Value(typeOf<String>()),
NameValueProperty<*>::value.name to valueColumnSchema,
),
)
},
Expand Down Expand Up @@ -443,7 +443,7 @@ private fun AnyFrame.isSingleUnnamedColumn() = columnsCount() == 1 && getColumn(
*
* @param records List of json elements to be converted to a [DataFrame].
* @param unifyNumbers Whether to [unify the numbers that are read][UnifyingNumbers].
* @param keyValuePaths List of [JsonPath]s where instead of a [ColumnGroup], a [FrameColumn]<[KeyValueProperty]>
* @param keyValuePaths List of [JsonPath]s where instead of a [ColumnGroup], a [FrameColumn]<[NameValueProperty]>
* will be created.
* @param header Optional list of column names. If given, [records] will be read like an object with [header] being the keys.
* @return [DataFrame] from the given [records].
Expand Down Expand Up @@ -527,16 +527,16 @@ internal fun fromJsonListArrayAndValueColumns(
.commonType()

dataFrameOf(
columnOf(*map.keys.toTypedArray()).named(KeyValueProperty<*>::key.name),
columnOf(*map.keys.toTypedArray()).named(NameValueProperty<*>::name.name),
createColumnGuessingType(
values = map.values,
suggestedType = TypeSuggestion.Use(valueType),
unifyNumbers = unifyNumbers,
).named(KeyValueProperty<*>::value.name),
).named(NameValueProperty<*>::value.name),
)
}

is JsonNull, null -> DataFrame.emptyOf<AnyKeyValueProperty>()
is JsonNull, null -> DataFrame.emptyOf<AnyNameValueProperty>()

else -> error("Expected JsonObject, got $record")
}
Expand Down
Loading