Skip to content

Commit f5d2db1

Browse files
map for column group tests
1 parent 70e180a commit f5d2db1

File tree

1 file changed

+16
-0
lines changed
  • core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api

1 file changed

+16
-0
lines changed

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
}

0 commit comments

Comments
 (0)