Skip to content

Commit 41cf7b5

Browse files
Merge branch 'master' into insert_kdocs
2 parents b618a44 + 85fdd63 commit 41cf7b5

File tree

7 files changed

+56
-4
lines changed

7 files changed

+56
-4
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.jetbrains.kotlinx.dataframe.Selector
1010
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
1111
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
1212
import org.jetbrains.kotlinx.dataframe.annotations.Refine
13+
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
1314
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
1415
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
1516
import org.jetbrains.kotlinx.dataframe.impl.columnName
@@ -25,7 +26,7 @@ import kotlin.reflect.typeOf
2526

2627
@Deprecated(DEPRECATED_ACCESS_API)
2728
@AccessApiOverload
28-
public inline fun <C, reified R> ColumnReference<C>.map(
29+
internal inline fun <C, reified R> ColumnReference<C>.map(
2930
infer: Infer = Infer.Nulls,
3031
noinline transform: (C) -> R,
3132
): ColumnReference<R> = createComputedColumnReference(name(), typeOf<R>(), infer) { transform(this@map()) }
@@ -69,6 +70,13 @@ public inline fun <T, R> DataColumn<T>.mapIndexed(
6970

7071
// region DataFrame
7172

73+
/**
74+
* Note: When this method is applied to a **[ColumnGroup]**,
75+
* its behavior differs from [DataColumn.map].
76+
* To apply `map` as if on a regular [DataColumn] (i.e., a column of [DataRow]s
77+
* whose values correspond to values in columns of the group),
78+
* call [ColumnGroup.asDataColumn] first.
79+
*/
7280
public inline fun <T, R> DataFrame<T>.map(transform: RowExpression<T, R>): List<R> = rows().map { transform(it, it) }
7381

7482
public inline fun <T, reified R> DataFrame<T>.mapToColumn(

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/map.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import io.kotest.matchers.shouldBe
4+
import org.jetbrains.kotlinx.dataframe.DataColumn
45
import org.junit.Test
56

67
class MapTests {
@@ -18,4 +19,19 @@ class MapTests {
1819
}
1920
df["b"][1] shouldBe 5
2021
}
22+
23+
@Test
24+
fun `ColumnGroup map`() {
25+
val group = dataFrameOf("x", "y")(1, 10, 2, 20, 3, 30).asColumnGroup("g")
26+
val sums = group.asDataFrame().map { row -> row["x"] as Int + row["y"] as Int }
27+
sums shouldBe listOf(11, 22, 33)
28+
}
29+
30+
@Test
31+
fun `ColumnGroup asDataColumn map`() {
32+
val group = dataFrameOf("x", "y")(1, 10, 2, 20, 3, 30).asColumnGroup("g")
33+
val col: DataColumn<Int> = group.asDataColumn().map { it["x"] as Int + it["y"] as Int }
34+
col.name() shouldBe "g"
35+
col.toList() shouldBe listOf(11, 22, 33)
36+
}
2137
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.jetbrains.kotlinx.dataframe.Selector
1010
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
1111
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
1212
import org.jetbrains.kotlinx.dataframe.annotations.Refine
13+
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
1314
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
1415
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
1516
import org.jetbrains.kotlinx.dataframe.impl.columnName
@@ -25,7 +26,7 @@ import kotlin.reflect.typeOf
2526

2627
@Deprecated(DEPRECATED_ACCESS_API)
2728
@AccessApiOverload
28-
public inline fun <C, reified R> ColumnReference<C>.map(
29+
internal inline fun <C, reified R> ColumnReference<C>.map(
2930
infer: Infer = Infer.Nulls,
3031
noinline transform: (C) -> R,
3132
): ColumnReference<R> = createComputedColumnReference(name(), typeOf<R>(), infer) { transform(this@map()) }
@@ -69,6 +70,13 @@ public inline fun <T, R> DataColumn<T>.mapIndexed(
6970

7071
// region DataFrame
7172

73+
/**
74+
* Note: When this method is applied to a **[ColumnGroup]**,
75+
* its behavior differs from [DataColumn.map].
76+
* To apply `map` as if on a regular [DataColumn] (i.e., a column of [DataRow]s
77+
* whose values correspond to values in columns of the group),
78+
* call [ColumnGroup.asDataColumn] first.
79+
*/
7280
public inline fun <T, R> DataFrame<T>.map(transform: RowExpression<T, R>): List<R> = rows().map { transform(it, it) }
7381

7482
public inline fun <T, reified R> DataFrame<T>.mapToColumn(

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/map.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import io.kotest.matchers.shouldBe
4+
import org.jetbrains.kotlinx.dataframe.DataColumn
45
import org.junit.Test
56

67
class MapTests {
@@ -18,4 +19,19 @@ class MapTests {
1819
}
1920
df["b"][1] shouldBe 5
2021
}
22+
23+
@Test
24+
fun `ColumnGroup map`() {
25+
val group = dataFrameOf("x", "y")(1, 10, 2, 20, 3, 30).asColumnGroup("g")
26+
val sums = group.asDataFrame().map { row -> row["x"] as Int + row["y"] as Int }
27+
sums shouldBe listOf(11, 22, 33)
28+
}
29+
30+
@Test
31+
fun `ColumnGroup asDataColumn map`() {
32+
val group = dataFrameOf("x", "y")(1, 10, 2, 20, 3, 30).asColumnGroup("g")
33+
val col: DataColumn<Int> = group.asDataColumn().map { it["x"] as Int + it["y"] as Int }
34+
col.name() shouldBe "g"
35+
col.toList() shouldBe listOf(11, 22, 33)
36+
}
2137
}

dataframe-json/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ dependencies {
2626
implementation(libs.serialization.json)
2727
implementation(libs.sl4j)
2828

29-
testImplementation(libs.kotlin.test)
29+
// Use Kotlin test integration for JUnit 5 to satisfy variant 'kotlin-test-framework-junit5'
30+
testImplementation(libs.kotlin.test.junit5)
3031
testImplementation(libs.junit.jupiter)
3132
testImplementation(libs.junit.jupiter.engine)
3233
testImplementation(libs.junit.jupiter.params)

docs/StardustDocs/topics/concepts/DataColumn.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ Currently, it uses [`List`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.
2727

2828
#### ColumnGroup
2929

30-
Container for nested columns. Is used to create column hierarchy.
30+
Container for nested columns. Used to create column hierarchy.
31+
32+
You can create column groups using the group operation or by splitting inward — see [group](group.md) and [split](split.md) for details.
3133

3234
#### FrameColumn
3335

gradle/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ kotlin-compiler = { group = "org.jetbrains.kotlin", name = "kotlin-compiler", ve
161161
kotlin-compiler-embeddable = { group = "org.jetbrains.kotlin", name = "kotlin-compiler-embeddable", version.ref = "kotlin" }
162162
kotlin-compiler-internal-test-framework = { group = "org.jetbrains.kotlin", name = "kotlin-compiler-internal-test-framework", version.ref = "kotlin" }
163163
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" }
164+
kotlin-test-junit5 = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit5", version.ref = "kotlin" }
164165
kotlin-script-runtime = { group = "org.jetbrains.kotlin", name = "kotlin-script-runtime", version.ref = "kotlin" }
165166
kotlin-annotations-jvm = { group = "org.jetbrains.kotlin", name = "kotlin-annotations-jvm", version.ref = "kotlin" }
166167
kotlin-jupyter-test-kit = { group = "org.jetbrains.kotlinx", name = "kotlin-jupyter-test-kit", version.ref = "kotlinJupyter" }

0 commit comments

Comments
 (0)