Skip to content

Commit c0e44e6

Browse files
committed
Add more specific explodeLists overload that helps to avoid unnecessary cast
1 parent 49d9e4e commit c0e44e6

File tree

3 files changed

+29
-0
lines changed
  • core

3 files changed

+29
-0
lines changed

core/api/core.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2381,6 +2381,7 @@ public final class org/jetbrains/kotlinx/dataframe/api/Gather {
23812381

23822382
public final class org/jetbrains/kotlinx/dataframe/api/GatherKt {
23832383
public static final fun explodeLists (Lorg/jetbrains/kotlinx/dataframe/api/Gather;)Lorg/jetbrains/kotlinx/dataframe/api/Gather;
2384+
public static final fun explodeListsTyped (Lorg/jetbrains/kotlinx/dataframe/api/Gather;)Lorg/jetbrains/kotlinx/dataframe/api/Gather;
23842385
public static final fun gather (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lkotlin/jvm/functions/Function2;)Lorg/jetbrains/kotlinx/dataframe/api/Gather;
23852386
public static final fun gather (Lorg/jetbrains/kotlinx/dataframe/DataFrame;[Ljava/lang/String;)Lorg/jetbrains/kotlinx/dataframe/api/Gather;
23862387
public static final fun gather (Lorg/jetbrains/kotlinx/dataframe/DataFrame;[Lkotlin/reflect/KProperty;)Lorg/jetbrains/kotlinx/dataframe/api/Gather;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ public fun <T, C, K, R> Gather<T, C, K, R>.explodeLists(): Gather<T, C, K, R> =
7171
explode = true,
7272
)
7373

74+
@JvmName("explodeListsTyped")
75+
@Interpretable("GatherExplodeLists")
76+
public fun <T, C, K, R> Gather<T, List<C>, K, R>.explodeLists(): Gather<T, C, K, R> =
77+
Gather(
78+
df = df,
79+
columns = columns,
80+
filter = filter,
81+
keyType = keyType,
82+
keyTransform = keyTransform,
83+
valueTransform = valueTransform,
84+
explode = true,
85+
) as Gather<T, C, K, R>
86+
7487
@Interpretable("GatherMap")
7588
public inline fun <T, C, reified K, R> Gather<T, C, *, R>.mapKeys(
7689
noinline transform: (String) -> K,

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,4 +187,19 @@ class GatherTests {
187187
"b", 5,
188188
)
189189
}
190+
191+
@Test
192+
fun `gather explode lists typed`() {
193+
val df = dataFrameOf("list" to columnOf(listOf(1, 2, 3)))
194+
.gather { "list"<List<Int>>() }
195+
.explodeLists()
196+
.mapValues { listOf(it) }
197+
.into("key", "value")
198+
199+
df shouldBe dataFrameOf("key", "value")(
200+
"list", listOf(1),
201+
"list", listOf(2),
202+
"list", listOf(3),
203+
)
204+
}
190205
}

0 commit comments

Comments
 (0)