Skip to content

Commit

Permalink
Merge pull request #1031 from Kotlin/acess-api-overload-1
Browse files Browse the repository at this point in the history
Add some AccessApiOverload annotations
  • Loading branch information
koperagen authored Jan 28, 2025
2 parents b4739b9 + 3769ca2 commit b3306cb
Show file tree
Hide file tree
Showing 25 changed files with 126 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,16 @@ public interface DataRow<out T> {

public operator fun <R> get(expression: RowExpression<T, R>): R = expression(this, this)

@AccessApiOverload
public operator fun <R> get(column: ColumnReference<R>): R

@AccessApiOverload
public operator fun <R> get(columns: List<ColumnReference<R>>): List<R> = columns.map { get(it) }

@AccessApiOverload
public operator fun <R> get(property: KProperty<R>): R = get(property.columnName) as R

@AccessApiOverload
public operator fun get(first: AnyColumnReference, vararg other: AnyColumnReference): DataRow<T> =
owner.get(first, *other)[index]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public fun AnyRow.namedValues(): List<NameValuePair<Any?>> =

public fun <T> AnyRow.getValue(columnName: String): T = get(columnName) as T

@AccessApiOverload
public fun <T> AnyRow.getValue(column: ColumnReference<T>): T = get(column)

@AccessApiOverload
Expand All @@ -75,6 +76,7 @@ public fun <T> AnyRow.getValueOrNull(column: KProperty<T>): T? = getValueOrNull<

public fun AnyRow.containsKey(columnName: String): Boolean = owner.containsColumn(columnName)

@AccessApiOverload
public fun AnyRow.containsKey(column: AnyColumnReference): Boolean = owner.containsColumn(column)

@AccessApiOverload
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.kotlinx.dataframe.AnyColumnReference
import org.jetbrains.kotlinx.dataframe.AnyFrame
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.indices
import kotlin.reflect.KProperty
Expand All @@ -19,9 +20,11 @@ public fun <T, C> DataFrame<T>.countDistinct(columns: ColumnsSelector<T, C>): In

public fun <T> DataFrame<T>.countDistinct(vararg columns: String): Int = countDistinct { columns.toColumnSet() }

@AccessApiOverload
public fun <T, C> DataFrame<T>.countDistinct(vararg columns: KProperty<C>): Int =
countDistinct { columns.toColumnSet() }

@AccessApiOverload
public fun <T> DataFrame<T>.countDistinct(vararg columns: AnyColumnReference): Int =
countDistinct { columns.toColumnSet() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.kotlinx.dataframe.AnyColumnReference
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.impl.nothingType
import org.jetbrains.kotlinx.dataframe.impl.nullableNothingType
Expand Down Expand Up @@ -87,11 +88,13 @@ public fun <T, C> DataFrame<T>.cumSum(
public fun <T> DataFrame<T>.cumSum(vararg columns: String, skipNA: Boolean = defaultCumSumSkipNA): DataFrame<T> =
cumSum(skipNA) { columns.toColumnSet() }

@AccessApiOverload
public fun <T> DataFrame<T>.cumSum(
vararg columns: AnyColumnReference,
skipNA: Boolean = defaultCumSumSkipNA,
): DataFrame<T> = cumSum(skipNA) { columns.toColumnSet() }

@AccessApiOverload
public fun <T> DataFrame<T>.cumSum(vararg columns: KProperty<*>, skipNA: Boolean = defaultCumSumSkipNA): DataFrame<T> =
cumSum(skipNA) { columns.toColumnSet() }

Expand All @@ -112,11 +115,13 @@ public fun <T, G, C> GroupBy<T, G>.cumSum(
public fun <T, G> GroupBy<T, G>.cumSum(vararg columns: String, skipNA: Boolean = defaultCumSumSkipNA): GroupBy<T, G> =
cumSum(skipNA) { columns.toColumnSet() }

@AccessApiOverload
public fun <T, G> GroupBy<T, G>.cumSum(
vararg columns: AnyColumnReference,
skipNA: Boolean = defaultCumSumSkipNA,
): GroupBy<T, G> = cumSum(skipNA) { columns.toColumnSet() }

@AccessApiOverload
public fun <T, G> GroupBy<T, G>.cumSum(
vararg columns: KProperty<*>,
skipNA: Boolean = defaultCumSumSkipNA,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jetbrains.kotlinx.dataframe.api
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
Expand Down Expand Up @@ -49,9 +50,11 @@ public fun <T> DataFrame<T>.describe(columns: ColumnsSelector<T, *>): DataFrame<
public fun <T> DataFrame<T>.describe(vararg columns: String): DataFrame<ColumnDescription> =
describe { columns.toColumnSet() }

@AccessApiOverload
public fun <T, C : Number?> DataFrame<T>.describe(vararg columns: ColumnReference<C>): DataFrame<ColumnDescription> =
describe { columns.toColumnSet() }

@AccessApiOverload
public fun <T, C : Number?> DataFrame<T>.describe(vararg columns: KProperty<C>): DataFrame<ColumnDescription> =
describe { columns.toColumnSet() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.RowFilter
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
Expand Down Expand Up @@ -202,6 +203,7 @@ public interface FirstColumnsSelectionDsl {
*
* `df.`[select][DataFrame.select]` { DataSchemaType::myColumnGroup.`[firstCol][KProperty.firstCol]`() }`
*/
@AccessApiOverload
public fun KProperty<*>.firstCol(condition: ColumnFilter<*> = { true }): TransformableSingleColumn<*> =
columnGroup(this).firstCol(condition)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.kotlinx.dataframe.AnyFrame
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.Predicate
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
Expand Down Expand Up @@ -159,6 +160,7 @@ public interface FrameColsColumnsSelectionDsl {
*
* `df.`[select][DataFrame.select]` { DataSchemaType::myColGroup.`[frameCols][KProperty.frameCols]`() }`
*/
@AccessApiOverload
public fun KProperty<*>.frameCols(
filter: Predicate<FrameColumn<*>> = { true },
): TransformableColumnSet<DataFrame<*>> = columnGroup(this).frameCols(filter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ public inline fun <T, reified R> DataFrame<T>.insert(
): InsertClause<T> = insert(mapToColumn(name, infer, expression))

@Interpretable("Insert2")
@AccessApiOverload
public inline fun <T, reified R> DataFrame<T>.insert(
column: ColumnAccessor<R>,
infer: Infer = Infer.Nulls,
noinline expression: RowExpression<T, R>,
): InsertClause<T> = insert(column.name(), infer, expression)

@Interpretable("Insert3")
@AccessApiOverload
public inline fun <T, reified R> DataFrame<T>.insert(
column: KProperty<R>,
infer: Infer = Infer.Nulls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.RowFilter
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
Expand Down Expand Up @@ -201,6 +202,7 @@ public interface LastColumnsSelectionDsl {
*
* `df.`[select][DataFrame.select]` { DataSchemaType::myColumnGroup.`[lastCol][KProperty.lastCol]`() }`
*/
@AccessApiOverload
public fun KProperty<*>.lastCol(condition: ColumnFilter<*> = { true }): TransformableSingleColumn<*> =
columnGroup(this).lastCol(condition)

Expand Down
13 changes: 13 additions & 0 deletions core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/max.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public fun <T, C : Comparable<C>> Grouped<T>.max(name: String? = null, columns:
public fun <T> Grouped<T>.max(vararg columns: String, name: String? = null): DataFrame<T> =
max(name) { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, C : Comparable<C>> Grouped<T>.max(
vararg columns: ColumnReference<C?>,
name: String? = null,
Expand Down Expand Up @@ -195,11 +196,13 @@ public fun <T, R : Comparable<R>> Pivot<T>.maxFor(
public fun <T> Pivot<T>.maxFor(vararg columns: String, separate: Boolean = false): DataRow<T> =
maxFor(separate) { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, R : Comparable<R>> Pivot<T>.maxFor(
vararg columns: ColumnReference<R?>,
separate: Boolean = false,
): DataRow<T> = maxFor(separate) { columns.toColumnSet() }

@AccessApiOverload
public fun <T, R : Comparable<R>> Pivot<T>.maxFor(
vararg columns: KProperty<R?>,
separate: Boolean = false,
Expand All @@ -209,9 +212,11 @@ public fun <T, R : Comparable<R>> Pivot<T>.max(columns: ColumnsSelector<T, R?>):

public fun <T> Pivot<T>.max(vararg columns: String): DataRow<T> = max { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, R : Comparable<R>> Pivot<T>.max(vararg columns: ColumnReference<R?>): DataRow<T> =
max { columns.toColumnSet() }

@AccessApiOverload
public fun <T, R : Comparable<R>> Pivot<T>.max(vararg columns: KProperty<R?>): DataRow<T> =
max { columns.toColumnSet() }

Expand All @@ -221,12 +226,14 @@ public fun <T, R : Comparable<R>> Pivot<T>.maxOf(rowExpression: RowExpression<T,
public fun <T, R : Comparable<R>> Pivot<T>.maxBy(rowExpression: RowExpression<T, R>): ReducedPivot<T> =
reduce { maxByOrNull(rowExpression) }

@AccessApiOverload
public fun <T, C : Comparable<C>> Pivot<T>.maxBy(column: ColumnReference<C?>): ReducedPivot<T> =
reduce { maxByOrNull(column) }

public fun <T> Pivot<T>.maxBy(column: String): ReducedPivot<T> =
maxBy(column.toColumnAccessor().cast<Comparable<Any?>>())

@AccessApiOverload
public fun <T, C : Comparable<C>> Pivot<T>.maxBy(column: KProperty<C?>): ReducedPivot<T> =
maxBy(column.toColumnAccessor())

Expand All @@ -244,11 +251,13 @@ public fun <T, R : Comparable<R>> PivotGroupBy<T>.maxFor(
public fun <T> PivotGroupBy<T>.maxFor(vararg columns: String, separate: Boolean = false): DataFrame<T> =
maxFor(separate) { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, R : Comparable<R>> PivotGroupBy<T>.maxFor(
vararg columns: ColumnReference<R?>,
separate: Boolean = false,
): DataFrame<T> = maxFor(separate) { columns.toColumnSet() }

@AccessApiOverload
public fun <T, R : Comparable<R>> PivotGroupBy<T>.maxFor(
vararg columns: KProperty<R?>,
separate: Boolean = false,
Expand All @@ -259,9 +268,11 @@ public fun <T, R : Comparable<R>> PivotGroupBy<T>.max(columns: ColumnsSelector<T

public fun <T> PivotGroupBy<T>.max(vararg columns: String): DataFrame<T> = max { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, R : Comparable<R>> PivotGroupBy<T>.max(vararg columns: ColumnReference<R?>): DataFrame<T> =
max { columns.toColumnSet() }

@AccessApiOverload
public fun <T, R : Comparable<R>> PivotGroupBy<T>.max(vararg columns: KProperty<R?>): DataFrame<T> =
max { columns.toColumnSet() }

Expand All @@ -271,12 +282,14 @@ public fun <T, R : Comparable<R>> PivotGroupBy<T>.maxOf(rowExpression: RowExpres
public fun <T, R : Comparable<R>> PivotGroupBy<T>.maxBy(rowExpression: RowExpression<T, R>): ReducedPivotGroupBy<T> =
reduce { maxByOrNull(rowExpression) }

@AccessApiOverload
public fun <T, C : Comparable<C>> PivotGroupBy<T>.maxBy(column: ColumnReference<C?>): ReducedPivotGroupBy<T> =
reduce { maxByOrNull(column) }

public fun <T> PivotGroupBy<T>.maxBy(column: String): ReducedPivotGroupBy<T> =
maxBy(column.toColumnAccessor().cast<Comparable<Any?>>())

@AccessApiOverload
public fun <T, C : Comparable<C>> PivotGroupBy<T>.maxBy(column: KProperty<C?>): ReducedPivotGroupBy<T> =
maxBy(column.toColumnAccessor())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public fun <T, C : Number> DataFrame<T>.meanFor(
public fun <T> DataFrame<T>.meanFor(vararg columns: String, skipNA: Boolean = skipNA_default): DataRow<T> =
meanFor(skipNA) { columns.toNumberColumns() }

@AccessApiOverload
public fun <T, C : Number> DataFrame<T>.meanFor(
vararg columns: ColumnReference<C?>,
skipNA: Boolean = skipNA_default,
Expand All @@ -79,6 +80,7 @@ public fun <T, C : Number> DataFrame<T>.mean(
public fun <T> DataFrame<T>.mean(vararg columns: String, skipNA: Boolean = skipNA_default): Double =
mean(skipNA) { columns.toNumberColumns() }

@AccessApiOverload
public fun <T, C : Number> DataFrame<T>.mean(
vararg columns: ColumnReference<C?>,
skipNA: Boolean = skipNA_default,
Expand Down Expand Up @@ -107,6 +109,7 @@ public fun <T, C : Number> Grouped<T>.meanFor(
public fun <T> Grouped<T>.meanFor(vararg columns: String, skipNA: Boolean = skipNA_default): DataFrame<T> =
meanFor(skipNA) { columns.toNumberColumns() }

@AccessApiOverload
public fun <T, C : Number> Grouped<T>.meanFor(
vararg columns: ColumnReference<C?>,
skipNA: Boolean = skipNA_default,
Expand All @@ -130,6 +133,7 @@ public fun <T> Grouped<T>.mean(
skipNA: Boolean = skipNA_default,
): DataFrame<T> = mean(name, skipNA) { columns.toNumberColumns() }

@AccessApiOverload
public fun <T, C : Number> Grouped<T>.mean(
vararg columns: ColumnReference<C?>,
name: String? = null,
Expand Down Expand Up @@ -168,6 +172,7 @@ public fun <T> Pivot<T>.meanFor(
separate: Boolean = false,
): DataRow<T> = meanFor(skipNA, separate) { columns.toNumberColumns() }

@AccessApiOverload
public fun <T, C : Number> Pivot<T>.meanFor(
vararg columns: ColumnReference<C?>,
skipNA: Boolean = skipNA_default,
Expand Down Expand Up @@ -210,6 +215,7 @@ public fun <T> PivotGroupBy<T>.meanFor(
skipNA: Boolean = skipNA_default,
): DataFrame<T> = meanFor(skipNA, separate) { columns.toNumberColumns() }

@AccessApiOverload
public fun <T, C : Number> PivotGroupBy<T>.meanFor(
vararg columns: ColumnReference<C?>,
separate: Boolean = false,
Expand All @@ -231,6 +237,7 @@ public fun <T, R : Number> PivotGroupBy<T>.mean(
public fun <T> PivotGroupBy<T>.mean(vararg columns: String, skipNA: Boolean = skipNA_default): DataFrame<T> =
mean(skipNA) { columns.toColumnsSetOf() }

@AccessApiOverload
public fun <T, R : Number> PivotGroupBy<T>.mean(
vararg columns: ColumnReference<R?>,
skipNA: Boolean = skipNA_default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public fun <T, C : Comparable<C>> DataFrame<T>.medianFor(columns: ColumnsForAggr

public fun <T> DataFrame<T>.medianFor(vararg columns: String): DataRow<T> = medianFor { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, C : Comparable<C>> DataFrame<T>.medianFor(vararg columns: ColumnReference<C?>): DataRow<T> =
medianFor { columns.toColumnSet() }

Expand All @@ -73,6 +74,7 @@ public fun <T, C : Comparable<C>> DataFrame<T>.median(columns: ColumnsSelector<T

public fun <T> DataFrame<T>.median(vararg columns: String): Any = median { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, C : Comparable<C>> DataFrame<T>.median(vararg columns: ColumnReference<C?>): C =
median { columns.toColumnSet() }

Expand All @@ -85,6 +87,7 @@ public fun <T, C : Comparable<C>> DataFrame<T>.medianOrNull(columns: ColumnsSele

public fun <T> DataFrame<T>.medianOrNull(vararg columns: String): Any? = medianOrNull { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, C : Comparable<C>> DataFrame<T>.medianOrNull(vararg columns: ColumnReference<C?>): C? =
medianOrNull { columns.toColumnSet() }

Expand All @@ -107,6 +110,7 @@ public fun <T, C : Comparable<C>> Grouped<T>.medianFor(columns: ColumnsForAggreg

public fun <T> Grouped<T>.medianFor(vararg columns: String): DataFrame<T> = medianFor { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, C : Comparable<C>> Grouped<T>.medianFor(vararg columns: ColumnReference<C?>): DataFrame<T> =
medianFor { columns.toColumnSet() }

Expand All @@ -122,6 +126,7 @@ public fun <T, C : Comparable<C>> Grouped<T>.median(
public fun <T> Grouped<T>.median(vararg columns: String, name: String? = null): DataFrame<T> =
median(name) { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, C : Comparable<C>> Grouped<T>.median(
vararg columns: ColumnReference<C?>,
name: String? = null,
Expand Down Expand Up @@ -150,6 +155,7 @@ public fun <T, C : Comparable<C>> Pivot<T>.medianFor(
public fun <T> Pivot<T>.medianFor(vararg columns: String, separate: Boolean = false): DataRow<T> =
medianFor(separate) { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, C : Comparable<C>> Pivot<T>.medianFor(
vararg columns: ColumnReference<C?>,
separate: Boolean = false,
Expand All @@ -166,6 +172,7 @@ public fun <T, C : Comparable<C>> Pivot<T>.median(columns: ColumnsSelector<T, C?

public fun <T> Pivot<T>.median(vararg columns: String): DataRow<T> = median { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, C : Comparable<C>> Pivot<T>.median(vararg columns: ColumnReference<C?>): DataRow<T> =
median { columns.toColumnSet() }

Expand All @@ -192,6 +199,7 @@ public fun <T, C : Comparable<C>> PivotGroupBy<T>.medianFor(
public fun <T> PivotGroupBy<T>.medianFor(vararg columns: String, separate: Boolean = false): DataFrame<T> =
medianFor(separate) { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, C : Comparable<C>> PivotGroupBy<T>.medianFor(
vararg columns: ColumnReference<C?>,
separate: Boolean = false,
Expand All @@ -208,6 +216,7 @@ public fun <T, C : Comparable<C>> PivotGroupBy<T>.median(columns: ColumnsSelecto

public fun <T> PivotGroupBy<T>.median(vararg columns: String): DataFrame<T> = median { columns.toComparableColumns() }

@AccessApiOverload
public fun <T, C : Comparable<C>> PivotGroupBy<T>.median(vararg columns: ColumnReference<C?>): DataFrame<T> =
median { columns.toColumnSet() }

Expand Down
Loading

0 comments on commit b3306cb

Please sign in to comment.