Skip to content

Commit 58704fe

Browse files
Merge branch 'master' into pivot_kdocs
2 parents 3d40ee3 + a2c7f5d commit 58704fe

File tree

7 files changed

+781
-32
lines changed

7 files changed

+781
-32
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/aggregation/AggregateDsl.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jetbrains.kotlinx.dataframe.aggregation
22

33
import org.jetbrains.kotlinx.dataframe.DataFrame
4+
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
45
import org.jetbrains.kotlinx.dataframe.annotations.HasSchema
56
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
67
import org.jetbrains.kotlinx.dataframe.api.ColumnSelectionDsl
@@ -9,6 +10,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
910
import org.jetbrains.kotlinx.dataframe.impl.aggregation.ValueWithDefault
1011
import org.jetbrains.kotlinx.dataframe.impl.aggregation.receivers.internal
1112
import org.jetbrains.kotlinx.dataframe.impl.columnName
13+
import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
1214
import kotlin.reflect.KProperty
1315
import kotlin.reflect.typeOf
1416

@@ -21,9 +23,13 @@ public abstract class AggregateDsl<out T> :
2123
public inline infix fun <reified R> R.into(name: String): NamedValue =
2224
internal().yield(pathOf(name), this, typeOf<R>())
2325

26+
@Deprecated(DEPRECATED_ACCESS_API)
27+
@AccessApiOverload
2428
public inline infix fun <reified R> R.into(column: ColumnAccessor<R>): NamedValue =
2529
internal().yield(pathOf(column.name()), this, typeOf<R>())
2630

31+
@Deprecated(DEPRECATED_ACCESS_API)
32+
@AccessApiOverload
2733
public inline infix fun <reified R> R.into(column: KProperty<R>): NamedValue =
2834
internal().yield(pathOf(column.columnName), this, typeOf<R>())
2935

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/group.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import kotlin.reflect.KProperty
1919
// region DataFrame
2020

2121
/**
22-
* Groups the specified [columns] within the [DataFrame].
22+
* Groups the specified [columns] within the [DataFrame] into
23+
* [column group][ColumnGroup].
2324
*
2425
* This function does not immediately group the columns but instead select columns to group and
2526
* returns a [GroupClause],
@@ -142,7 +143,8 @@ internal interface GroupDocs {
142143
}
143144

144145
/**
145-
* Groups the specified [columns] within the [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame].
146+
* Groups the specified [columns] within the [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] into
147+
* [column group][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup].
146148
*
147149
* This function does not immediately group the columns but instead select columns to group and
148150
* returns a [GroupClause][org.jetbrains.kotlinx.dataframe.api.GroupClause],
@@ -197,7 +199,8 @@ internal interface GroupDocs {
197199
public fun <T, C> DataFrame<T>.group(columns: ColumnsSelector<T, C>): GroupClause<T, C> = GroupClause(this, columns)
198200

199201
/**
200-
* Groups the specified [columns] within the [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame].
202+
* Groups the specified [columns] within the [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] into
203+
* [column group][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup].
201204
*
202205
* This function does not immediately group the columns but instead select columns to group and
203206
* returns a [GroupClause][org.jetbrains.kotlinx.dataframe.api.GroupClause],

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/groupBy.kt

Lines changed: 715 additions & 5 deletions
Large diffs are not rendered by default.

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/pivot.kt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,37 @@ internal fun <T> Pivot<T>.reduce(reducer: Selector<DataFrame<T>, DataRow<T>?>):
275275
internal inline fun <T> Pivot<T>.delegate(crossinline body: PivotGroupBy<T>.() -> DataFrame<T>): DataRow<T> =
276276
body(groupBy { none() })[0]
277277

278+
/**
279+
* TODO (#1536)
280+
*/
281+
internal interface PivotGroupByDocs {
282+
283+
/**
284+
* [PivotGroupBy] is a dataframe-like structure, combining [Pivot] and [GroupBy]
285+
* and representing a matrix table with vertical [Pivot] groups (as columns)
286+
* and horizontal [GroupBy] groups (as rows), and each cell
287+
* represents a group corresponding both to [GroupBy] and [Pivot] key.
288+
*
289+
* Reversed order of `pivot` and `groupBy`
290+
* (i.e., [DataFrame.pivot] + [Pivot.groupBy] or [DataFrame.groupBy] + [GroupBy.pivot])
291+
* will produce the same result.
292+
*
293+
* [PivotGroupBy] can be [reduced][PivotGroupByDocs.Reducing]
294+
* or [aggregated][PivotGroupByDocs.Aggregation].
295+
*
296+
* Check out [PivotGroupBy Grammar][PivotGroupByDocs.Grammar].
297+
*
298+
* For more information: [See "`pivot` + `groupBy`" on the documentation website.](https://kotlin.github.io/dataframe/groupby.html#pivot-groupby)
299+
*/
300+
interface CommonDescription
301+
302+
interface Grammar
303+
304+
interface Reducing
305+
306+
interface Aggregation
307+
}
308+
278309
public interface PivotGroupBy<out T> : Aggregatable<T> {
279310

280311
public fun <R> aggregate(separate: Boolean = false, body: AggregateBody<T, R>): DataFrame<T>

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import kotlin.reflect.KProperty
3838
/**
3939
* Groups the rows of this [DataFrame] based on the values in one or more specified [key columns][cols].
4040
* Each unique value in a key column — or a unique tuple of values for multiple columns —
41-
* defines a group consisting of all rows where the column(s) contain that value combination.
41+
* defines the group consisting of all rows where the column(s) contain that value combination.
4242
*
4343
* Returns a [GroupBy] — a dataframe-like structure that contains all unique combinations of key values
4444
* along with the corresponding groups of rows (each represented as a [DataFrame]) as rows.
@@ -79,40 +79,40 @@ internal interface GroupByDocs {
7979
*
8080
* ### Create and transform [GroupBy]
8181
*
82-
* [**`groupBy`**][groupBy]**`(`**`moveToTop: `[`Boolean`][Boolean]**` = true) { `**`columns: `[`ColumnsSelector`][ColumnsSelector]**` }`**
82+
* [**`groupBy`**][groupBy]**`(`**`moveToTop: `[`Boolean`][Boolean]**` = true) { `**`columns: `[`ColumnsSelector`][ColumnsSelector]**` }`**
8383
*
8484
* {@include [Indent]}
85-
* `\[ `__`.`__[**`sortByGroup`**][GroupBy.sortByGroup]**`() `**
85+
* `\[ `__`.`__[**`sortByGroup`**][GroupBy.sortByGroup]**`() `**`]`
8686
*
8787
* {@include [Indent]}
88-
* `| `__`.`__[**`sortByGroupDesc`**][GroupBy.sortByGroupDesc]**`() `**
88+
* `\[ `__`.`__[**`sortByGroupDesc`**][GroupBy.sortByGroupDesc]**`() `**`]`
8989
*
9090
* {@include [Indent]}
91-
* `| `__`.`__[**`sortByCount`**][GroupBy.sortByCount]**`() `**
91+
* `\[ `__`.`__[**`sortByCount`**][GroupBy.sortByCount]**`() `**`]`
9292
*
9393
* {@include [Indent]}
94-
* `| `__`.`__[**`sortByCountAsc`**][GroupBy.sortByCountAsc]**`() `**
94+
* `\[ `__`.`__[**`sortByCountAsc`**][GroupBy.sortByCountAsc]**`() `**`]`
9595
*
9696
* {@include [Indent]}
97-
* `| `__`.`__[**`sortByKey`**][GroupBy.sortByKey]**`() `**
97+
* `\[ `__`.`__[**`sortByKey`**][GroupBy.sortByKey]**`() `**`]`
9898
*
9999
* {@include [Indent]}
100-
* `| `__`.`__[**`sortByKeyDesc`**][GroupBy.sortByKeyDesc]**`() `**`]`
100+
* `\[ `__`.`__[**`sortByKeyDesc`**][GroupBy.sortByKeyDesc]**`() `**`]`
101101
*
102102
* {@include [Indent]}
103-
* `\[ `__`.`__[**`sortBy`**][GroupBy.sortBy]**` { `**`columns: `[`ColumnsSelector`][ColumnsSelector]**` } `**
103+
* `\[ `__`.`__[**`sortBy`**][GroupBy.sortBy]**` { `**`columns: `[`ColumnsSelector`][ColumnsSelector]**` } `**`]`
104104
*
105105
* {@include [Indent]}
106-
* `| `__`.`__[**`sortByDesc`**][GroupBy.sortByDesc]**` { `**`columns: `[`ColumnsSelector`][ColumnsSelector]**` } `**`]`
106+
* `\[ `__`.`__[**`sortByDesc`**][GroupBy.sortByDesc]**` { `**`columns: `[`ColumnsSelector`][ColumnsSelector]**` } `**`]`
107107
*
108108
* {@include [Indent]}
109-
* `\[ `__`.`__[**`updateGroups`**][GroupBy.updateGroups]**` { `**`frameExpression`**` } `**`]`
109+
* `\[ `__`.`__[**`updateGroups`**][GroupBy.updateGroups]**` { `**`frameExpression`**` } `**`]`
110110
*
111111
* {@include [Indent]}
112-
* `\[ `__`.`__[**`filter`**][GroupBy.filter]**` { `**`predicate: `[`GroupedRowFilter`][GroupedRowFilter]**` } `**`]`
112+
* `\[ `__`.`__[**`filter`**][GroupBy.filter]**` { `**`predicate: `[`GroupedRowFilter`][GroupedRowFilter]**` } `**`]`
113113
*
114114
* {@include [Indent]}
115-
* `\[ `__`.`__[**`add`**][GroupBy.add]**`(`**`column: `[`DataColumn`][DataColumn]**`) { `**`rowExpression: `[`RowExpression`][RowExpression]**` } `**`]`
115+
* `\[ `__`.`__[**`add`**][GroupBy.add]**`(`**`column: `[`DataColumn`][DataColumn]**`) { `**`rowExpression: `[`RowExpression`][RowExpression]**` } `**`]`
116116
*
117117
* ### Reduce [GroupBy] into [DataFrame]
118118
*
@@ -123,10 +123,10 @@ internal interface GroupByDocs {
123123
* `| `__`.`__[**`maxBy`**][GroupBy.maxBy]**` { `**`column: `[`ColumnSelector`][ColumnSelector]**` }`**
124124
*
125125
* {@include [Indent]}
126-
* `| `__`.`__[**`first`**][GroupBy.first]` \[ `**` { `**`rowCondition: `[`RowFilter`][RowFilter]**` } `**`]`
126+
* `| `__`.`__[**`first`**][GroupBy.first]` \[ `**` { `**`rowCondition: `[`RowFilter`][RowFilter]**` } `**`]`
127127
*
128128
* {@include [Indent]}
129-
* `| `__`.`__[**`last`**][GroupBy.last]` \[ `**`{ `**`rowCondition: `[`RowFilter`][RowFilter]**` } `**`]`
129+
* `| `__`.`__[**`last`**][GroupBy.last]` \[ `**` { `**`rowCondition: `[`RowFilter`][RowFilter]**` } `**`]`
130130
*
131131
* {@include [Indent]}
132132
* __`.`__[**`concat`**][ReducedGroupBy.concat]**`() `**
@@ -234,7 +234,7 @@ internal interface GroupByDocs {
234234
* * [sortBy][GroupBy.sortBy] / [sortByDesc][GroupBy.sortByDesc] — sorts the **order of rows within each group**
235235
* by one or more column values;
236236
* * [updateGroups][GroupBy.updateGroups] — transforms each group into a new one;
237-
* * [filter][GroupBy.filter] — filters group rows by the given predicate (as usual [DataFrame.filter]).
237+
* * [filter][GroupBy.filter] — filters group rows by the given predicate (as usual [DataFrame.filter]);
238238
* * [add][GroupBy.add] — adds a new column to each group.
239239
*
240240
* Each method returns a new [GroupBy] with updated group order or modified group content.
@@ -392,7 +392,7 @@ public fun <T> DataFrame<T>.groupBy(vararg cols: AnyColumnReference, moveToTop:
392392
* @include [PivotGroupByDocs.CommonDescription]
393393
*/
394394
@ExcludeFromSources
395-
internal interface GroupByForPivotDocs
395+
private interface GroupByForPivotDocs
396396

397397
/**
398398
* {@include [GroupByForPivotDocs]}
@@ -508,7 +508,7 @@ public val <T, G> GroupedDataRow<T, G>.group: DataFrame<G>
508508
public data class GroupWithKey<T, G>(val key: DataRow<T>, val group: DataFrame<G>)
509509

510510
/**
511-
* A dataframe-like structure that contains all unique combinations of key values
511+
* A dataframe-like structure that contains all unique combinations of key-values
512512
* along with the corresponding groups of rows (each represented as a [DataFrame]).
513513
*
514514
* Consists of two main parts:
@@ -571,7 +571,7 @@ public interface GroupBy<out T, out G> : Grouped<G> {
571571
* a row from [keys] and its corresponding group of rows (as [DataFrame]).
572572
*
573573
* If [groupedColumnName] is provided, the groups will be stored
574-
* in a [FrameColumn] with that name; otherwise, a default name is used.
574+
* in a [FrameColumn] with that name; otherwise, a default name "group" is used.
575575
*
576576
* @param groupedColumnName The name of the column in which to store grouped data;
577577
* if `null`, a default name will be used.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,9 @@ internal fun <T> Pivot<T>.reduce(reducer: Selector<DataFrame<T>, DataRow<T>?>):
743743
internal inline fun <T> Pivot<T>.delegate(crossinline body: PivotGroupBy<T>.() -> DataFrame<T>): DataRow<T> =
744744
body(groupBy { none() })[0]
745745

746+
/**
747+
* TODO (#1536)
748+
*/
746749
internal interface PivotGroupByDocs {
747750

748751
/**

docs/StardustDocs/topics/groupBy.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,7 @@ df.groupBy { name }.concat()
142142
<inline-frame src="resources/org.jetbrains.kotlinx.dataframe.samples.api.Modify.concatGroupBy.html" width="100%"/>
143143
<!---END-->
144144

145-
## Reducing
146-
147-
TODO
148-
149-
## Aggregation
145+
<!---TODO ## Reducing--->
150146

151147
To compute one or several [statistics](summaryStatistics.md) per every group of `GroupBy` use `aggregate` function.
152148
Its body will be executed for every data group and has a receiver of type [`DataFrame`](DataFrame.md) that represents current data group being aggregated.

0 commit comments

Comments
 (0)