@@ -2,7 +2,9 @@ package org.jetbrains.kotlinx.dataframe.api
2
2
3
3
import org.jetbrains.kotlinx.dataframe.AnyColumnReference
4
4
import org.jetbrains.kotlinx.dataframe.AnyFrame
5
+ import org.jetbrains.kotlinx.dataframe.BuildConfig
5
6
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
7
+ import org.jetbrains.kotlinx.dataframe.DataColumn
6
8
import org.jetbrains.kotlinx.dataframe.DataFrame
7
9
import org.jetbrains.kotlinx.dataframe.DataRow
8
10
import org.jetbrains.kotlinx.dataframe.Selector
@@ -13,6 +15,7 @@ import org.jetbrains.kotlinx.dataframe.annotations.Refine
13
15
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
14
16
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
15
17
import org.jetbrains.kotlinx.dataframe.impl.aggregation.PivotImpl
18
+ import org.jetbrains.kotlinx.dataframe.impl.api.GroupByEntryImpl
16
19
import org.jetbrains.kotlinx.dataframe.impl.api.getPivotColumnPaths
17
20
import org.jetbrains.kotlinx.dataframe.impl.api.groupByImpl
18
21
import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
@@ -71,17 +74,46 @@ public fun <T> Pivot<T>.groupByOther(): PivotGroupBy<T> {
71
74
72
75
// endregion
73
76
77
+ @Deprecated(" Replaced by GroupByEntrySelector" )
74
78
public typealias GroupedRowSelector <T , G , R > = GroupedDataRow <T , G >.(GroupedDataRow <T , G >) -> R
75
79
80
+ @Deprecated(" Replaced by GroupByEntryFilter" )
76
81
public typealias GroupedRowFilter <T , G > = GroupedRowSelector <T , G , Boolean >
77
82
83
+ @Deprecated(" Replaced by GroupByEntry" )
78
84
public interface GroupedDataRow <out T , out G > : DataRow <T > {
79
85
80
86
public fun group (): DataFrame <G >
81
87
}
82
88
83
89
public val <T , G > GroupedDataRow <T , G >.group: DataFrame <G > get() = group()
84
90
91
+ /* *
92
+ * Represents a single combination of keys+group in a [GroupBy] instance.
93
+ *
94
+ * `this` is a [DataRow] representing the keys of the current group, while the [group()][group]
95
+ * function points to the group that corresponds to the keys of this entry.
96
+ *
97
+ * For example:
98
+ * ```kotlin
99
+ * df.groupBy { name and age }.forEachEntry { // this|it: GroupByEntry<T, G> ->
100
+ * println("There are \${group().rowsCount()} instances of \$name")
101
+ * }
102
+ * ```
103
+ */
104
+ public interface GroupByEntry <out T , out G > : DataRow <T > {
105
+
106
+ /* * Returns the [DataFrame] representing the group that corresponds to the keys of this entry. */
107
+ public fun group (): DataFrame <G >
108
+
109
+ // TODO?
110
+ public fun keys (): Map <String , Any ?> = this .toMap()
111
+ }
112
+
113
+ public typealias GroupByEntrySelector <T , G , R > = GroupByEntry <T , G >.(GroupByEntry <T , G >) -> R
114
+ public typealias GroupByEntryFilter <T , G > = GroupByEntrySelector <T , G , Boolean >
115
+
116
+ @Deprecated(" Replaced by GroupByEntry" )
85
117
public data class GroupWithKey <T , G >(val key : DataRow <T >, val group : DataFrame <G >)
86
118
87
119
public interface GroupBy <out T , out G > : Grouped <G > {
@@ -92,12 +124,14 @@ public interface GroupBy<out T, out G> : Grouped<G> {
92
124
93
125
public fun <R > updateGroups (transform : Selector <DataFrame <G >, DataFrame <R >>): GroupBy <T , R >
94
126
127
+ @Deprecated(" Replaced by filterEntries" )
95
128
public fun filter (predicate : GroupedRowFilter <T , G >): GroupBy <T , G >
96
129
97
130
@Refine
98
131
@Interpretable(" GroupByToDataFrame" )
99
132
public fun toDataFrame (groupedColumnName : String? = null): DataFrame <T >
100
133
134
+ @Deprecated(" " )
101
135
public data class Entry <T , G >(val key : DataRow <T >, val group : DataFrame <G >)
102
136
103
137
public companion object {
0 commit comments