Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 32 additions & 23 deletions core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/pivot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,9 @@ internal interface DataFramePivotMatchesCommonDocs

/**
* @include [DataFramePivotMatchesCommonDocs]
* @include [SelectingColumns.Dsl]
* Select or express pivot columns using the [PivotDsl].
*
* @include [PivotDslDocs]
* ### Example
* ```kotlin
* // Compute whether matching rows exist for all unique values of "city"
Expand All @@ -498,11 +499,11 @@ internal interface DataFramePivotMatchesCommonDocs
*
* @param [inward] If `true` (default), the generated pivoted columns are nested inside the original column;
* if `false`, they are placed at the top level.
* @param [columns] The [Columns Selector][ColumnsSelector] that defines which columns are used as [pivot] keys for the operation.
* @param [columns] The [Pivot Columns Selector][PivotColumnsSelector] that defines which columns are used as [pivot] keys for the operation.
* @return A new [DataFrame] representing a [Boolean] presence matrix — with grouping key columns as rows,
* pivot key values as columns, and `true`/`false` cells indicating existing combinations.
*/
public fun <T> DataFrame<T>.pivotMatches(inward: Boolean = true, columns: ColumnsSelector<T, *>): DataFrame<T> =
public fun <T> DataFrame<T>.pivotMatches(inward: Boolean = true, columns: PivotColumnsSelector<T, *>): DataFrame<T> =
pivot(inward, columns).groupByOther().matches()

/**
Expand Down Expand Up @@ -577,7 +578,9 @@ internal interface DataFramePivotCountsCommonDocs

/**
* @include [DataFramePivotCountsCommonDocs]
* @include [SelectingColumns.Dsl]
* Select or express pivot columns using the [PivotDsl].
*
* @include [PivotDslDocs]
*
* ### Example
* ```kotlin
Expand All @@ -588,11 +591,11 @@ internal interface DataFramePivotCountsCommonDocs
* ```
*
* @include [PivotDocs.InwardKDocs]
* @param [columns] The [Columns Selector][ColumnsSelector] that defines which columns are used as [pivot] keys for the operation.
* @param [columns] The [Pivot Columns Selector][PivotColumnsSelector] that defines which columns are used as [pivot] keys for the operation.
* @return A new [DataFrame] representing a counting matrix — with grouping key columns as rows,
* pivot key values as columns, and the number of rows with the corresponding combinations in the cells.
*/
public fun <T> DataFrame<T>.pivotCounts(inward: Boolean = true, columns: ColumnsSelector<T, *>): DataFrame<T> =
public fun <T> DataFrame<T>.pivotCounts(inward: Boolean = true, columns: PivotColumnsSelector<T, *>): DataFrame<T> =
pivot(inward, columns).groupByOther().count()

/**
Expand Down Expand Up @@ -655,11 +658,11 @@ private interface CommonPivotForGroupByDocs
* @include [CommonPivotForGroupByDocs]
* @include [SelectingColumns.Dsl.WithExample] {@include [SetPivotOperationArg] {@set [SelectingColumns.RECEIVER] <code>`gb`</code>}}
* @include [PivotDocs.InwardKDocsForGrouped]
* @param [columns] The [Columns Selector][ColumnsSelector] that defines which columns are pivoted.
* @param [columns] The [Pivot Columns Selector][PivotColumnsSelector] that defines which columns are pivoted.
* @return A new [PivotGroupBy] that preserves the original [groupBy] key columns
* and pivots the provided columns.
*/
public fun <G> GroupBy<*, G>.pivot(inward: Boolean = true, columns: ColumnsSelector<G, *>): PivotGroupBy<G> =
public fun <G> GroupBy<*, G>.pivot(inward: Boolean = true, columns: PivotColumnsSelector<G, *>): PivotGroupBy<G> =
PivotGroupByImpl(this, columns, inward)

@Deprecated(DEPRECATED_ACCESS_API)
Expand Down Expand Up @@ -713,7 +716,9 @@ internal interface GroupByPivotMatchesCommonDocs

/**
* @include [GroupByPivotMatchesCommonDocs]
* @include [SelectingColumns.Dsl]
* Select or express pivot columns using the [PivotDsl].
*
* @include [PivotDslDocs]
*
* ### Example
* ```kotlin
Expand All @@ -723,11 +728,11 @@ internal interface GroupByPivotMatchesCommonDocs
* ```
*
* @include [PivotDocs.InwardKDocsForGrouped]
* @param [columns] The [Columns Selector][ColumnsSelector] that defines which columns are used as [pivot] keys for the operation.
* @param [columns] The [Pivot Columns Selector][PivotColumnsSelector] that defines which columns are used as [pivot] keys for the operation.
* @return A new [DataFrame] representing a Boolean presence matrix — with grouping key columns as rows,
* pivot key values as columns, and `true`/`false` cells indicating existing combinations.
*/
public fun <G> GroupBy<*, G>.pivotMatches(inward: Boolean = true, columns: ColumnsSelector<G, *>): DataFrame<G> =
public fun <G> GroupBy<*, G>.pivotMatches(inward: Boolean = true, columns: PivotColumnsSelector<G, *>): DataFrame<G> =
pivot(inward, columns).matches()

/**
Expand Down Expand Up @@ -787,7 +792,9 @@ internal interface GroupByPivotCountsCommonDocs

/**
* @include [GroupByPivotCountsCommonDocs]
* @include [SelectingColumns.Dsl]
* Select or express pivot columns using the [PivotDsl].
*
* @include [PivotDslDocs]
*
* ### Example
* ```kotlin
Expand All @@ -797,11 +804,11 @@ internal interface GroupByPivotCountsCommonDocs
* ```
*
* @include [PivotDocs.InwardKDocsForGrouped]
* @param [columns] The [Columns Selector][ColumnsSelector] that defines which columns are used as [pivot] keys for the operation.
* @param [columns] The [Pivot Columns Selector][PivotColumnsSelector] that defines which columns are used as [pivot] keys for the operation.
* @return A new [DataFrame] representing a counting matrix — with grouping key columns as rows,
* pivot key values as columns, and the number of rows with the corresponding combinations in the cells.
*/
public fun <G> GroupBy<*, G>.pivotCounts(inward: Boolean = true, columns: ColumnsSelector<G, *>): DataFrame<G> =
public fun <G> GroupBy<*, G>.pivotCounts(inward: Boolean = true, columns: PivotColumnsSelector<G, *>): DataFrame<G> =
pivot(inward, columns).count()

/**
Expand Down Expand Up @@ -936,8 +943,7 @@ public fun <T> AggregateGroupedDsl<T>.pivot(
* ```
*
* @include [PivotDocs.InwardKDocsForGrouped]
* @param columns The [Pivot Columns Selector][PivotColumnsSelector] that defines which columns are used
* as keys for pivoting and in which order.
* @param [columns] The [Column Names][String] that defines which columns are used as [pivot] keys for the operation.
* @return A [PivotGroupBy] for further [aggregations][PivotGroupByDocs.Aggregation].
*/
public fun <T> AggregateGroupedDsl<T>.pivot(vararg columns: String, inward: Boolean = true): PivotGroupBy<T> =
Expand Down Expand Up @@ -983,7 +989,9 @@ internal interface AggregateGroupedDslPivotMatchesDocs

/**
* @include [AggregateGroupedDslPivotMatchesDocs]
* @include [SelectingColumns.Dsl]
* Select or express pivot columns using the [PivotDsl].
*
* @include [PivotDslDocs]
* ### Example
* ```kotlin
* df.groupBy { name.firstName }.aggregate {
Expand All @@ -994,15 +1002,15 @@ internal interface AggregateGroupedDslPivotMatchesDocs
* ```
*
* @include [PivotDocs.InwardKDocsForGrouped]
* @param columns The [Columns Selector][ColumnsSelector] that defines which columns are used
* @param columns The [Pivot Columns Selector][PivotColumnsSelector] that defines which columns are used
* as keys for pivoting and in which order.
* @return A new [DataFrame] representing a Boolean presence matrix — with grouping key columns as rows,
* pivot key values as columns, and `true`/`false` cells indicating existing combinations.
* This [DataFrame] is added to the [aggregate][Grouped.aggregate] result.
*/
public fun <T> AggregateGroupedDsl<T>.pivotMatches(
inward: Boolean = true,
columns: ColumnsSelector<T, *>,
columns: PivotColumnsSelector<T, *>,
): DataFrame<T> = pivot(inward, columns).matches()

/**
Expand Down Expand Up @@ -1067,10 +1075,11 @@ internal interface AggregateGroupedDslPivotCountsDocs

/**
* @include [AggregateGroupedDslPivotCountsDocs]
* @include [SelectingColumns.Dsl]
* Select or express pivot columns using the [PivotDsl].
*
* @include [PivotDslDocs]
* ### Example
* ```kotlin
* ```kotlin
* df.groupBy { name.firstName }.aggregate {
* // Compute number of for all unique values of "city"
* // across all "name.firstName" key values and adds it to the aggregation result
Expand All @@ -1079,15 +1088,15 @@ internal interface AggregateGroupedDslPivotCountsDocs
* ```
*
* @include [PivotDocs.InwardKDocsForGrouped]
* @param columns The [Columns Selector][ColumnsSelector] that defines which columns are used
* @param columns The [Pivot Columns Selector][PivotColumnsSelector] that defines which columns are used
* as keys for pivoting and in which order.
* @return A new [DataFrame] representing a counting matrix — with grouping key columns as rows,
* pivot key values as columns, and the number of rows with the corresponding combinations in the cells.
* This [DataFrame] is added to the [aggregate][Grouped.aggregate] result.
*/
public fun <T> AggregateGroupedDsl<T>.pivotCounts(
inward: Boolean = true,
columns: ColumnsSelector<T, *>,
columns: PivotColumnsSelector<T, *>,
): DataFrame<T> = pivot(inward, columns).count()

/**
Expand Down