Skip to content

Commit 5b4d2bc

Browse files
authored
Revert "Merging KeyValueProperty and NameValuePair"
1 parent de6c30a commit 5b4d2bc

File tree

9 files changed

+20
-75
lines changed

9 files changed

+20
-75
lines changed

core/api/core.api

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,8 +1948,6 @@ public final class org/jetbrains/kotlinx/dataframe/api/DataFrameGetKt {
19481948
}
19491949

19501950
public final class org/jetbrains/kotlinx/dataframe/api/DataRowApiKt {
1951-
public static final fun NameValuePairAny_key (Lorg/jetbrains/kotlinx/dataframe/ColumnsContainer;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
1952-
public static final fun NameValuePairAny_key (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
19531951
public static final fun NameValuePairAny_name (Lorg/jetbrains/kotlinx/dataframe/ColumnsContainer;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
19541952
public static final fun NameValuePairAny_name (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
19551953
public static final fun NameValuePairAny_value (Lorg/jetbrains/kotlinx/dataframe/ColumnsContainer;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
@@ -1962,8 +1960,6 @@ public final class org/jetbrains/kotlinx/dataframe/api/DataRowApiKt {
19621960
public static final fun containsKey (Lorg/jetbrains/kotlinx/dataframe/DataRow;Ljava/lang/String;)Z
19631961
public static final fun containsKey (Lorg/jetbrains/kotlinx/dataframe/DataRow;Lkotlin/reflect/KProperty;)Z
19641962
public static final fun containsKey (Lorg/jetbrains/kotlinx/dataframe/DataRow;Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;)Z
1965-
public static final fun copy (Lorg/jetbrains/kotlinx/dataframe/api/NameValuePair;Ljava/lang/String;Ljava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/api/NameValuePair;
1966-
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;
19671963
public static final fun diff (Lorg/jetbrains/kotlinx/dataframe/DataRow;DLkotlin/jvm/functions/Function2;)D
19681964
public static final fun diff (Lorg/jetbrains/kotlinx/dataframe/DataRow;FLkotlin/jvm/functions/Function2;)F
19691965
public static final fun diff (Lorg/jetbrains/kotlinx/dataframe/DataRow;ILkotlin/jvm/functions/Function2;)I
@@ -1972,7 +1968,6 @@ public final class org/jetbrains/kotlinx/dataframe/api/DataRowApiKt {
19721968
public static final fun diffOrNull (Lorg/jetbrains/kotlinx/dataframe/DataRow;Lkotlin/jvm/functions/Function2;)Ljava/lang/Float;
19731969
public static final fun diffOrNull (Lorg/jetbrains/kotlinx/dataframe/DataRow;Lkotlin/jvm/functions/Function2;)Ljava/lang/Integer;
19741970
public static final fun diffOrNull (Lorg/jetbrains/kotlinx/dataframe/DataRow;Lkotlin/jvm/functions/Function2;)Ljava/lang/Long;
1975-
public static final fun getName (Lorg/jetbrains/kotlinx/dataframe/api/NameValuePair;)Ljava/lang/String;
19761971
public static final fun getRow (Lorg/jetbrains/kotlinx/dataframe/DataRow;I)Lorg/jetbrains/kotlinx/dataframe/DataRow;
19771972
public static final fun getRowOrNull (Lorg/jetbrains/kotlinx/dataframe/DataRow;I)Lorg/jetbrains/kotlinx/dataframe/DataRow;
19781973
public static final fun getRows (Lorg/jetbrains/kotlinx/dataframe/DataRow;Ljava/lang/Iterable;)Lorg/jetbrains/kotlinx/dataframe/DataFrame;
@@ -3471,31 +3466,26 @@ public final class org/jetbrains/kotlinx/dataframe/api/MoveKt {
34713466
public static final fun under (Lorg/jetbrains/kotlinx/dataframe/api/MoveClause;Lorg/jetbrains/kotlinx/dataframe/columns/ColumnAccessor;)Lorg/jetbrains/kotlinx/dataframe/DataFrame;
34723467
}
34733468

3474-
public final class org/jetbrains/kotlinx/dataframe/api/NameValuePair : org/jetbrains/kotlinx/dataframe/api/KeyValueProperty {
3475-
public static final field Companion Lorg/jetbrains/kotlinx/dataframe/api/NameValuePair$Companion;
3469+
public final class org/jetbrains/kotlinx/dataframe/api/NameValuePair {
34763470
public fun <init> (Ljava/lang/String;Ljava/lang/Object;)V
34773471
public final fun component1 ()Ljava/lang/String;
34783472
public final fun component2 ()Ljava/lang/Object;
34793473
public final fun copy (Ljava/lang/String;Ljava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/api/NameValuePair;
34803474
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;
34813475
public fun equals (Ljava/lang/Object;)Z
3482-
public fun getKey ()Ljava/lang/String;
3483-
public fun getValue ()Ljava/lang/Object;
3476+
public final fun getName ()Ljava/lang/String;
3477+
public final fun getValue ()Ljava/lang/Object;
34843478
public fun hashCode ()I
34853479
public fun toString ()Ljava/lang/String;
34863480
}
34873481

3488-
public final class org/jetbrains/kotlinx/dataframe/api/NameValuePair$Companion {
3489-
public final fun invoke (Ljava/lang/String;Ljava/lang/Object;)Lorg/jetbrains/kotlinx/dataframe/api/NameValuePair;
3490-
}
3491-
34923482
public final class org/jetbrains/kotlinx/dataframe/api/NameValuePair_ExtensionsKt {
3493-
public static final fun NameValuePair_key (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
3494-
public static final fun NameValuePair_key (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
3483+
public static final fun NameValuePair_name (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
3484+
public static final fun NameValuePair_name (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
34953485
public static final fun NameValuePair_value (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
34963486
public static final fun NameValuePair_value (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Object;
3497-
public static final fun NullableNameValuePair_key (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
3498-
public static final fun NullableNameValuePair_key (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
3487+
public static final fun NullableNameValuePair_name (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
3488+
public static final fun NullableNameValuePair_name (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/String;
34993489
public static final fun NullableNameValuePair_value (Lorg/jetbrains/kotlinx/dataframe/ColumnsScope;)Lorg/jetbrains/kotlinx/dataframe/DataColumn;
35003490
public static final fun NullableNameValuePair_value (Lorg/jetbrains/kotlinx/dataframe/DataRow;)Ljava/lang/Object;
35013491
}

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/DataRowApi.kt

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import org.jetbrains.kotlinx.dataframe.util.GET_ROW_REPLACE
2525
import org.jetbrains.kotlinx.dataframe.util.IS_EMPTY_REPLACE
2626
import org.jetbrains.kotlinx.dataframe.util.IS_NOT_EMPTY_REPLACE
2727
import org.jetbrains.kotlinx.dataframe.util.MESSAGE_SHORTCUT
28-
import org.jetbrains.kotlinx.dataframe.util.NAME_VALUE_PAIR
2928
import kotlin.experimental.ExperimentalTypeInference
3029
import kotlin.reflect.KProperty
3130
import kotlin.reflect.KType
@@ -40,52 +39,18 @@ public fun AnyRow.isNotEmpty(): Boolean = !isEmpty()
4039
public inline fun <reified R> AnyRow.valuesOf(): List<R> = values().filterIsInstance<R>()
4140

4241
// region DataSchema
43-
44-
/**
45-
* Instantiatable [KeyValueProperty] representing a key-value pair [DataSchema] for a [DataFrame].
46-
*
47-
* [NameValuePair] may be deprecated in favor of an instantiatable [KeyValueProperty] class in the future.
48-
*
49-
* @param V type of the value
50-
* @param key the name of the key column (previously called `name`)
51-
* @param value the name of the value column
52-
*/
5342
@DataSchema
5443
@RequiredByIntellijPlugin
55-
public data class NameValuePair<V>(override val key: String, override val value: V) : KeyValueProperty<V> {
56-
public companion object {
57-
@Deprecated(NAME_VALUE_PAIR, level = DeprecationLevel.WARNING)
58-
public operator fun <V> invoke(name: String, value: V): NameValuePair<V> = NameValuePair(name, value)
59-
}
60-
}
61-
62-
@Deprecated(NAME_VALUE_PAIR, ReplaceWith("key"), level = DeprecationLevel.WARNING)
63-
public val NameValuePair<*>.name: String
64-
get() = key
65-
66-
@Deprecated(NAME_VALUE_PAIR, ReplaceWith("this.copy(name, value)"), level = DeprecationLevel.WARNING)
67-
public fun <V> NameValuePair<V>.copy(name: String = this.key, value: V = this.value): NameValuePair<V> =
68-
NameValuePair(key = name, value = value)
44+
public data class NameValuePair<V>(val name: String, val value: V)
6945

7046
// Without these overloads row.transpose().name or row.map { name } won't resolve
71-
72-
@Deprecated(NAME_VALUE_PAIR, ReplaceWith("this.key"), level = DeprecationLevel.WARNING)
7347
public val ColumnsContainer<NameValuePair<*>>.name: DataColumn<String>
7448
@JvmName("NameValuePairAny_name")
75-
get() = this["key"] as DataColumn<String>
49+
get() = this["name"] as DataColumn<String>
7650

77-
@Deprecated(NAME_VALUE_PAIR, ReplaceWith("this.key"), level = DeprecationLevel.WARNING)
7851
public val DataRow<NameValuePair<*>>.name: String
7952
@JvmName("NameValuePairAny_name")
80-
get() = this["key"] as String
81-
82-
public val ColumnsContainer<NameValuePair<*>>.key: DataColumn<String>
83-
@JvmName("NameValuePairAny_key")
84-
get() = this["key"] as DataColumn<String>
85-
86-
public val DataRow<NameValuePair<*>>.key: String
87-
@JvmName("NameValuePairAny_key")
88-
get() = this["key"] as String
53+
get() = this["name"] as String
8954

9055
public val ColumnsContainer<NameValuePair<*>>.value: DataColumn<*>
9156
@JvmName("NameValuePairAny_value")

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/KeyValueProperty.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ package org.jetbrains.kotlinx.dataframe.api
33
import org.jetbrains.kotlinx.dataframe.annotations.ColumnName
44
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
55

6-
/**
7-
* A [DataSchema] interface / class can implement this if it represents a map-like data schema (so key: value).
8-
* @see [NameValuePair]
9-
*/
6+
/** A [DataSchema] interface / class can implement this if it represents a map-like data schema (so key: value). */
107
@DataSchema
118
public interface KeyValueProperty<T> {
129
// needs to be explicitly overridden in @DataSchema interface, otherwise extension functions won't generate (TODO)

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/transpose.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ import kotlin.reflect.typeOf
1414
// region DataRow
1515

1616
public fun <T> DataRow<T>.transpose(): DataFrame<NameValuePair<*>> {
17-
val valueColumn = DataColumn.createByInference(KeyValueProperty<*>::value.columnName, values)
18-
val nameColumn = owner.columnNames().toValueColumn(KeyValueProperty<*>::key.name)
17+
val valueColumn = DataColumn.createByInference(NameValuePair<*>::value.columnName, values)
18+
val nameColumn = owner.columnNames().toValueColumn(NameValuePair<*>::name.name)
1919
return dataFrameOf(nameColumn, valueColumn).cast()
2020
}
2121

@@ -24,8 +24,8 @@ public inline fun <reified T> AnyRow.transposeTo(): DataFrame<NameValuePair<T>>
2424
@PublishedApi
2525
internal fun <T> AnyRow.transposeTo(type: KType): DataFrame<NameValuePair<T>> {
2626
val convertedValues = values.map { it?.convertTo(type) as T? }
27-
val valueColumn = DataColumn.createByInference(KeyValueProperty<T>::value.columnName, convertedValues)
28-
val nameColumn = owner.columnNames().toValueColumn(KeyValueProperty<T>::key.name)
27+
val valueColumn = DataColumn.createByInference(NameValuePair<T>::value.columnName, convertedValues)
28+
val nameColumn = owner.columnNames().toValueColumn(NameValuePair<T>::name.name)
2929
return dataFrameOf(nameColumn, valueColumn).cast()
3030
}
3131

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,9 +263,6 @@ internal const val COPY_REPLACE = "columns().toDataFrame().cast()"
263263
internal const val LISTS_TO_DATAFRAME_MIGRATION =
264264
"Function moved from io to api package, and a new `header` parameter is introduced. $MESSAGE_1_1"
265265

266-
internal const val NAME_VALUE_PAIR =
267-
"'name' of NameValuePair will be renamed to 'key' to align with KeyValueProperty, Issue #659. $MESSAGE_1_1"
268-
269266
// endregion
270267

271268
// region keep across releases

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/puzzles/MediumTests.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import org.jetbrains.kotlinx.dataframe.api.diffOrNull
1212
import org.jetbrains.kotlinx.dataframe.api.filter
1313
import org.jetbrains.kotlinx.dataframe.api.groupBy
1414
import org.jetbrains.kotlinx.dataframe.api.isNaN
15-
import org.jetbrains.kotlinx.dataframe.api.key
1615
import org.jetbrains.kotlinx.dataframe.api.map
1716
import org.jetbrains.kotlinx.dataframe.api.mapToColumn
1817
import org.jetbrains.kotlinx.dataframe.api.minBy
@@ -79,8 +78,8 @@ class MediumTests {
7978
.sum()
8079
.transposeTo<Double>()
8180
.minBy { value }
82-
.key shouldBe "b"
83-
df.sum().transpose().minBy("value")["key"] shouldBe "b"
81+
.name shouldBe "b"
82+
df.sum().transpose().minBy("value")["name"] shouldBe "b"
8483
}
8584

8685
@Test

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/animals/AnimalsTests.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import io.kotest.matchers.doubles.shouldBeNaN
44
import io.kotest.matchers.shouldBe
55
import org.jetbrains.kotlinx.dataframe.api.columnOf
66
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
7-
import org.jetbrains.kotlinx.dataframe.api.key
87
import org.jetbrains.kotlinx.dataframe.api.mean
98
import org.jetbrains.kotlinx.dataframe.api.name
109
import org.jetbrains.kotlinx.dataframe.api.transpose
@@ -34,7 +33,7 @@ class AnimalsTests {
3433
val mean = df.mean().transpose()
3534
mean.columnsCount() shouldBe 2
3635
mean.rowsCount() shouldBe 2
37-
mean.key.values() shouldBe listOf("age", "visits")
36+
mean.name.values() shouldBe listOf("age", "visits")
3837
mean.value.type() shouldBe typeOf<Double>()
3938
}
4039

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ import org.jetbrains.kotlinx.dataframe.api.isEmpty
8585
import org.jetbrains.kotlinx.dataframe.api.isFrameColumn
8686
import org.jetbrains.kotlinx.dataframe.api.isNA
8787
import org.jetbrains.kotlinx.dataframe.api.isNumber
88-
import org.jetbrains.kotlinx.dataframe.api.key
8988
import org.jetbrains.kotlinx.dataframe.api.keysInto
9089
import org.jetbrains.kotlinx.dataframe.api.last
9190
import org.jetbrains.kotlinx.dataframe.api.leftJoin
@@ -2602,7 +2601,7 @@ class DataFrameTests : BaseTest() {
26022601
typed[2]
26032602
.transpose()
26042603
.dropNulls { value }
2605-
.key
2604+
.name
26062605
.toList() shouldBe listOf("name", "age", "city")
26072606
}
26082607

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataRowTests.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import org.jetbrains.kotlinx.dataframe.api.drop
1010
import org.jetbrains.kotlinx.dataframe.api.dropLast
1111
import org.jetbrains.kotlinx.dataframe.api.first
1212
import org.jetbrains.kotlinx.dataframe.api.intoList
13-
import org.jetbrains.kotlinx.dataframe.api.key
1413
import org.jetbrains.kotlinx.dataframe.api.mapToColumn
1514
import org.jetbrains.kotlinx.dataframe.api.merge
1615
import org.jetbrains.kotlinx.dataframe.api.name
@@ -110,7 +109,7 @@ class DataRowTests : BaseTest() {
110109
@Test
111110
fun transposeTo() {
112111
val df = dataFrameOf("a", "b")(1, 2).first().transposeTo<Int>()
113-
df.key.toList() shouldBe listOf("a", "b")
112+
df.name.toList() shouldBe listOf("a", "b")
114113
df.value.toList() shouldBe listOf(1, 2)
115114
}
116115

0 commit comments

Comments
 (0)