Skip to content

Commit d333c73

Browse files
committed
Make GroupBy.Entry.group not nullable. Remove redundant GroupBy.forEach overload.
1 parent c5462fe commit d333c73

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/forEach.kt

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package org.jetbrains.kotlinx.dataframe.api
22

33
import org.jetbrains.kotlinx.dataframe.DataColumn
44
import org.jetbrains.kotlinx.dataframe.DataFrame
5-
import org.jetbrains.kotlinx.dataframe.DataRow
65
import org.jetbrains.kotlinx.dataframe.RowExpression
76
import org.jetbrains.kotlinx.dataframe.columns.values
87

@@ -22,15 +21,9 @@ public fun <T> DataFrame<T>.forEach(action: RowExpression<T, Unit>): Unit = rows
2221

2322
// region GroupBy
2423

25-
public fun <T, G> GroupBy<T, G>.forEach(body: (GroupBy.Entry<T, G>) -> Unit): Unit = forEach { key, group ->
26-
body(
27-
GroupBy.Entry(key, group)
28-
)
24+
public fun <T, G> GroupBy<T, G>.forEach(body: (GroupBy.Entry<T, G>) -> Unit): Unit = keys.forEach { key ->
25+
val group = groups[key.index()]
26+
body(GroupBy.Entry(key, group))
2927
}
30-
public fun <T, G> GroupBy<T, G>.forEach(body: (key: DataRow<T>, group: DataFrame<G>?) -> Unit): Unit =
31-
keys.forEach { row ->
32-
val group = groups[row.index()]
33-
body(row, group)
34-
}
3528

3629
// endregion

src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/groupBy.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public interface GroupBy<out T, out G> : Grouped<G> {
6666

6767
public fun filter(predicate: GroupedRowFilter<T, G>): GroupBy<T, G>
6868

69-
public data class Entry<T, G>(val key: DataRow<T>, val group: DataFrame<G>?)
69+
public data class Entry<T, G>(val key: DataRow<T>, val group: DataFrame<G>)
7070

7171
public companion object {
7272
internal val groupedColumnAccessor = column<AnyFrame>("group")

src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/pivot.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ internal fun <T, R> aggregatePivot(
8181
val effectiveInward = inward ?: if (aggregator.hasGroupingKeys) true else (pivotSequences.distinctBy { it.first().column.path }.count() > 1)
8282
pivotSequences.forEach { pivotColumns ->
8383

84-
aggregator.df.groupBy(pivotColumns.map { it.column }).forEach { key, group ->
84+
aggregator.df.groupBy(pivotColumns.map { it.column }).forEach { (key, group) ->
8585

8686
val pathNames = mutableListOf<String>()
8787
key.values().forEachIndexed { i, v ->
@@ -90,7 +90,7 @@ internal fun <T, R> aggregatePivot(
9090
pathNames.add(v.toString())
9191
}
9292
val path = pathNames.toPath()
93-
val builder = AggregatePivotDslImpl(group!!)
93+
val builder = AggregatePivotDslImpl(group)
9494
val result = body(builder, builder)
9595
val hasResult = result != null && result != Unit
9696

tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTreeTests.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import org.jetbrains.kotlinx.dataframe.api.explode
4040
import org.jetbrains.kotlinx.dataframe.api.expr
4141
import org.jetbrains.kotlinx.dataframe.api.filter
4242
import org.jetbrains.kotlinx.dataframe.api.forEach
43-
import org.jetbrains.kotlinx.dataframe.api.forEach
4443
import org.jetbrains.kotlinx.dataframe.api.frameColumn
4544
import org.jetbrains.kotlinx.dataframe.api.getColumnGroup
4645
import org.jetbrains.kotlinx.dataframe.api.getColumnPath

0 commit comments

Comments
 (0)