@@ -13,10 +13,11 @@ import org.jetbrains.kotlinx.dataframe.api.concat
13
13
import org.jetbrains.kotlinx.dataframe.api.convert
14
14
import org.jetbrains.kotlinx.dataframe.api.getColumn
15
15
import org.jetbrains.kotlinx.dataframe.api.getColumnsWithPaths
16
+ import org.jetbrains.kotlinx.dataframe.api.into
16
17
import org.jetbrains.kotlinx.dataframe.api.isColumnGroup
17
18
import org.jetbrains.kotlinx.dataframe.api.minus
18
19
import org.jetbrains.kotlinx.dataframe.api.pathOf
19
- import org.jetbrains.kotlinx.dataframe.api.toDataFrame
20
+ import org.jetbrains.kotlinx.dataframe.api.rename
20
21
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
21
22
import org.jetbrains.kotlinx.dataframe.impl.aggregation.AggregatableInternal
22
23
import org.jetbrains.kotlinx.dataframe.impl.aggregation.GroupByReceiverImpl
@@ -30,26 +31,14 @@ import org.jetbrains.kotlinx.dataframe.ncol
30
31
import org.jetbrains.kotlinx.dataframe.nrow
31
32
import org.jetbrains.kotlinx.dataframe.values
32
33
33
- /* *
34
- * Internal implementation interface for [GroupBy].
35
- *
36
- * While [df] should be hidden in the [GroupBy] DSL, it must be accessible when running
37
- * [GroupBy.toDataFrame].
38
- *
39
- * This interface is public to allow Kandy to implement it.
40
- */
41
- public interface GroupByInternal <T , G > : GroupBy <T , G > {
42
- public val df: DataFrame <T >
43
- }
44
-
45
34
/* *
46
35
* @property df DataFrame containing [groups] column and key columns. Represents GroupBy.
47
36
*/
48
37
internal class GroupByImpl <T , G >(
49
- override val df : DataFrame <T >,
38
+ val df : DataFrame <T >,
50
39
override val groups : FrameColumn <G >,
51
40
internal val keyColumnsInGroups : ColumnsSelector <G , * >,
52
- ) : GroupByInternal <T, G>,
41
+ ) : GroupBy <T, G>,
53
42
AggregatableInternal <G > {
54
43
55
44
override val keys by lazy { df - groups }
@@ -69,6 +58,13 @@ internal class GroupByImpl<T, G>(
69
58
}
70
59
return df[indices].asGroupBy(groups)
71
60
}
61
+
62
+ override fun toDataFrame (groupedColumnName : String? ): DataFrame <T > =
63
+ if (groupedColumnName == null || groupedColumnName == groups.name()) {
64
+ df
65
+ } else {
66
+ df.rename(groups).into(groupedColumnName)
67
+ }
72
68
}
73
69
74
70
internal fun <T , G , R > aggregateGroupBy (
0 commit comments