Skip to content

Commit de6c30a

Browse files
Automated commit of generated code
1 parent 84e044f commit de6c30a

File tree

8 files changed

+58
-13
lines changed

8 files changed

+58
-13
lines changed

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ 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
2829
import kotlin.experimental.ExperimentalTypeInference
2930
import kotlin.reflect.KProperty
3031
import kotlin.reflect.KType
@@ -39,18 +40,52 @@ public fun AnyRow.isNotEmpty(): Boolean = !isEmpty()
3940
public inline fun <reified R> AnyRow.valuesOf(): List<R> = values().filterIsInstance<R>()
4041

4142
// 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+
*/
4253
@DataSchema
4354
@RequiredByIntellijPlugin
44-
public data class NameValuePair<V>(val name: String, val value: V)
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)
4569

4670
// 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)
4773
public val ColumnsContainer<NameValuePair<*>>.name: DataColumn<String>
4874
@JvmName("NameValuePairAny_name")
49-
get() = this["name"] as DataColumn<String>
75+
get() = this["key"] as DataColumn<String>
5076

77+
@Deprecated(NAME_VALUE_PAIR, ReplaceWith("this.key"), level = DeprecationLevel.WARNING)
5178
public val DataRow<NameValuePair<*>>.name: String
5279
@JvmName("NameValuePairAny_name")
53-
get() = this["name"] as String
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
5489

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

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

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

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

core/generated-sources/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(NameValuePair<*>::value.columnName, values)
18-
val nameColumn = owner.columnNames().toValueColumn(NameValuePair<*>::name.name)
17+
val valueColumn = DataColumn.createByInference(KeyValueProperty<*>::value.columnName, values)
18+
val nameColumn = owner.columnNames().toValueColumn(KeyValueProperty<*>::key.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(NameValuePair<T>::value.columnName, convertedValues)
28-
val nameColumn = owner.columnNames().toValueColumn(NameValuePair<T>::name.name)
27+
val valueColumn = DataColumn.createByInference(KeyValueProperty<T>::value.columnName, convertedValues)
28+
val nameColumn = owner.columnNames().toValueColumn(KeyValueProperty<T>::key.name)
2929
return dataFrameOf(nameColumn, valueColumn).cast()
3030
}
3131

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ 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+
266269
// endregion
267270

268271
// region keep across releases

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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
1516
import org.jetbrains.kotlinx.dataframe.api.map
1617
import org.jetbrains.kotlinx.dataframe.api.mapToColumn
1718
import org.jetbrains.kotlinx.dataframe.api.minBy
@@ -78,8 +79,8 @@ class MediumTests {
7879
.sum()
7980
.transposeTo<Double>()
8081
.minBy { value }
81-
.name shouldBe "b"
82-
df.sum().transpose().minBy("value")["name"] shouldBe "b"
82+
.key shouldBe "b"
83+
df.sum().transpose().minBy("value")["key"] shouldBe "b"
8384
}
8485

8586
@Test

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ 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
78
import org.jetbrains.kotlinx.dataframe.api.mean
89
import org.jetbrains.kotlinx.dataframe.api.name
910
import org.jetbrains.kotlinx.dataframe.api.transpose
@@ -33,7 +34,7 @@ class AnimalsTests {
3334
val mean = df.mean().transpose()
3435
mean.columnsCount() shouldBe 2
3536
mean.rowsCount() shouldBe 2
36-
mean.name.values() shouldBe listOf("age", "visits")
37+
mean.key.values() shouldBe listOf("age", "visits")
3738
mean.value.type() shouldBe typeOf<Double>()
3839
}
3940

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ 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
8889
import org.jetbrains.kotlinx.dataframe.api.keysInto
8990
import org.jetbrains.kotlinx.dataframe.api.last
9091
import org.jetbrains.kotlinx.dataframe.api.leftJoin
@@ -2601,7 +2602,7 @@ class DataFrameTests : BaseTest() {
26012602
typed[2]
26022603
.transpose()
26032604
.dropNulls { value }
2604-
.name
2605+
.key
26052606
.toList() shouldBe listOf("name", "age", "city")
26062607
}
26072608

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ 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
1314
import org.jetbrains.kotlinx.dataframe.api.mapToColumn
1415
import org.jetbrains.kotlinx.dataframe.api.merge
1516
import org.jetbrains.kotlinx.dataframe.api.name
@@ -109,7 +110,7 @@ class DataRowTests : BaseTest() {
109110
@Test
110111
fun transposeTo() {
111112
val df = dataFrameOf("a", "b")(1, 2).first().transposeTo<Int>()
112-
df.name.toList() shouldBe listOf("a", "b")
113+
df.key.toList() shouldBe listOf("a", "b")
113114
df.value.toList() shouldBe listOf(1, 2)
114115
}
115116

0 commit comments

Comments
 (0)