|
1 | 1 | package org.jetbrains.kotlinx.dataframe.api
|
2 | 2 |
|
3 | 3 | import io.kotest.matchers.shouldBe
|
| 4 | +import org.jetbrains.kotlinx.dataframe.impl.commonType |
4 | 5 | import org.junit.Test
|
5 | 6 | import kotlin.reflect.typeOf
|
6 | 7 |
|
@@ -168,4 +169,20 @@ class PivotTests {
|
168 | 169 | }
|
169 | 170 | df1 shouldBe df.pivot { "category2" then "category3" }.groupBy("category1").count()
|
170 | 171 | }
|
| 172 | + |
| 173 | + @Test |
| 174 | + fun `pivot with default of other type`() { |
| 175 | + val df = dataFrameOf("firstName", "lastName", "age", "city", "weight", "isHappy")( |
| 176 | + "Alice", "Cooper", 15, "London", 54, true, |
| 177 | + "Bob", "Dylan", 45, "Dubai", 87, true, |
| 178 | + "Charlie", "Daniels", 20, "Moscow", null, false, |
| 179 | + "Charlie", "Chaplin", 40, "Milan", null, true, |
| 180 | + "Bob", "Marley", 30, "Tokyo", 68, true, |
| 181 | + "Alice", "Wolf", 20, null, 55, false, |
| 182 | + "Charlie", "Byrd", 30, "Moscow", 90, true |
| 183 | + ).group("firstName", "lastName").into("name") |
| 184 | + |
| 185 | + val pivoted = df.pivot("city").groupBy("name").default(0).min() |
| 186 | + pivoted["city"]["London"]["isHappy"].type() shouldBe listOf(typeOf<Int>(), typeOf<Boolean>()).commonType() |
| 187 | + } |
171 | 188 | }
|
0 commit comments