Skip to content

Commit

Permalink
Merge pull request #828 from Kotlin/multiplex-objects-public-api
Browse files Browse the repository at this point in the history
Hide properties of intermediate objects and remove data class attributes
  • Loading branch information
koperagen authored Aug 20, 2024
2 parents bb55f83 + f7251dd commit 5d88bb2
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ public inline fun <T, C, reified R> Convert<T, C?>.notNull(
}

@HasSchema(schemaArg = 0)
public data class Convert<T, out C>(val df: DataFrame<T>, val columns: ColumnsSelector<T, C>) {
public class Convert<T, out C>(internal val df: DataFrame<T>, internal val columns: ColumnsSelector<T, C>) {
public fun <R> cast(): Convert<T, R> = Convert(df, columns as ColumnsSelector<T, R>)

@Interpretable("To0")
public inline fun <reified D> to(): DataFrame<T> = to(typeOf<D>())

override fun toString(): String = "Convert(df=$df, columns=$columns)"
}

public fun <T> Convert<T, *>.to(type: KType): DataFrame<T> = to { it.convertTo(type) }
Expand Down
18 changes: 11 additions & 7 deletions core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public fun <T, C> FormatClause<T, C>.perRowCol(formatter: RowColFormatter<T, C>)
public fun <T, C> FormatClause<T, C>.with(formatter: CellFormatter<C>): FormattedFrame<T> =
formatImpl { row, col -> formatter(row[col]) }

public fun <T, C> FormatClause<T, C>.where(filter: RowValueFilter<T, C>): FormatClause<T, C> = copy(filter = filter)
public fun <T, C> FormatClause<T, C>.where(filter: RowValueFilter<T, C>): FormatClause<T, C> =
FormatClause(filter = filter, df = df, columns = columns, oldFormatter = oldFormatter)

public fun <T> FormattedFrame<T>.format(): FormatClause<T, Any?> = FormatClause(df, null, formatter)

Expand Down Expand Up @@ -129,12 +130,15 @@ public class FormattedFrame<T>(internal val df: DataFrame<T>, internal val forma
configuration.copy(cellFormatter = formatter as RowColFormatter<*, *>?)
}

public data class FormatClause<T, C>(
val df: DataFrame<T>,
val columns: ColumnsSelector<T, C>? = null,
val oldFormatter: RowColFormatter<T, C>? = null,
val filter: RowValueFilter<T, C> = { true },
)
public class FormatClause<T, C>(
internal val df: DataFrame<T>,
internal val columns: ColumnsSelector<T, C>? = null,
internal val oldFormatter: RowColFormatter<T, C>? = null,
internal val filter: RowValueFilter<T, C> = { true },
) {
override fun toString(): String =
"FormatClause(df=$df, columns=$columns, oldFormatter=$oldFormatter, filter=$filter)"
}

public fun <T, C> FormattedFrame<T>.format(columns: ColumnsSelector<T, C>): FormatClause<T, C> =
FormatClause(df, columns, formatter)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public fun <T> DataFrame<T>.group(vararg columns: KProperty<*>): GroupClause<T,

// region GroupClause

public data class GroupClause<T, C>(val df: DataFrame<T>, val columns: ColumnsSelector<T, C>)
public class GroupClause<T, C>(internal val df: DataFrame<T>, internal val columns: ColumnsSelector<T, C>) {
override fun toString(): String = "GroupClause(df=$df, columns=$columns)"
}

// region into

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ internal fun <T, G> GroupBy<T, G>.internal(): GroupByImpl<T, G> = this as GroupB

public interface Grouped<out T> : Aggregatable<T>

public data class ReducedGroupBy<T, G>(
public class ReducedGroupBy<T, G>(
@PublishedApi internal val groupBy: GroupBy<T, G>,
@PublishedApi internal val reducer: Selector<DataFrame<G>, DataRow<G>?>,
)
) {
override fun toString(): String = "ReducedGroupBy(groupBy=$groupBy, reducer=$reducer)"
}

internal fun <T, G> GroupBy<T, G>.reduce(reducer: Selector<DataFrame<G>, DataRow<G>?>) = ReducedGroupBy(this, reducer)
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ public inline fun <T, reified R> DataFrame<T>.insert(

// endregion

public data class InsertClause<T>(val df: DataFrame<T>, val column: AnyCol)
public class InsertClause<T>(internal val df: DataFrame<T>, internal val column: AnyCol) {
override fun toString(): String = "InsertClause(df=$df, column=$column)"
}

// region under

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ public fun <T, C> MoveClause<T, C>.toLeft(): DataFrame<T> = to(0)

public fun <T, C> MoveClause<T, C>.toRight(): DataFrame<T> = to(df.ncol)

public class MoveClause<T, C>(internal val df: DataFrame<T>, internal val columns: ColumnsSelector<T, C>)
public class MoveClause<T, C>(internal val df: DataFrame<T>, internal val columns: ColumnsSelector<T, C>) {
override fun toString(): String = "MoveClause(df=$df, columns=$columns)"
}

// endregion
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,12 @@ public interface Pivot<T> : Aggregatable<T>

public typealias PivotColumnsSelector<T, C> = Selector<PivotDsl<T>, ColumnsResolver<C>>

public data class ReducedPivot<T>(
public class ReducedPivot<T>(
@PublishedApi internal val pivot: Pivot<T>,
@PublishedApi internal val reducer: Selector<DataFrame<T>, DataRow<T>?>,
)
) {
override fun toString(): String = "ReducedPivot(pivot=$pivot, reducer=$reducer)"
}

internal fun <T> Pivot<T>.reduce(reducer: Selector<DataFrame<T>, DataRow<T>?>) = ReducedPivot(this, reducer)

Expand All @@ -230,10 +232,12 @@ public interface PivotGroupBy<out T> : Aggregatable<T> {
public fun default(value: Any?): PivotGroupBy<T>
}

public data class ReducedPivotGroupBy<T>(
public class ReducedPivotGroupBy<T>(
@PublishedApi internal val pivot: PivotGroupBy<T>,
@PublishedApi internal val reducer: Selector<DataFrame<T>, DataRow<T>?>,
)
) {
override fun toString(): String = "ReducedPivotGroupBy(pivot=$pivot, reducer=$reducer)"
}

@PublishedApi
internal fun <T> PivotGroupBy<T>.reduce(reducer: Selector<DataFrame<T>, DataRow<T>?>): ReducedPivotGroupBy<T> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public fun <T, C> DataFrame<T>.rename(vararg cols: KProperty<C>): RenameClause<T
public fun <T> DataFrame<T>.rename(vararg cols: String): RenameClause<T, Any?> = rename { cols.toColumnSet() }

@HasSchema(schemaArg = 0)
public data class RenameClause<T, C>(val df: DataFrame<T>, val columns: ColumnsSelector<T, C>)
public class RenameClause<T, C>(internal val df: DataFrame<T>, internal val columns: ColumnsSelector<T, C>) {
override fun toString(): String = "RenameClause(df=$df, columns=$columns)"
}

/**
* ## Rename to camelCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public fun <T> DataFrame<T>.replaceAll(
return update(columns).with { map[it] ?: it }
}

public data class ReplaceClause<T, C>(val df: DataFrame<T>, val columns: ColumnsSelector<T, C>)
public class ReplaceClause<T, C>(internal val df: DataFrame<T>, internal val columns: ColumnsSelector<T, C>) {
override fun toString(): String = "ReplaceClause(df=$df, columns=$columns)"
}

public fun <T, C> ReplaceClause<T, C>.with(vararg columns: AnyCol): DataFrame<T> = with(columns.toList())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ public fun <T, C> DataFrame<T>.split(vararg columns: ColumnReference<C?>): Split

public fun <T, C> DataFrame<T>.split(vararg columns: KProperty<C?>): Split<T, C> = split { columns.toColumnSet() }

public data class Split<T, C>(internal val df: DataFrame<T>, internal val columns: ColumnsSelector<T, C?>) {
public class Split<T, C>(internal val df: DataFrame<T>, internal val columns: ColumnsSelector<T, C?>) {
public fun <P> cast(): Split<T, P> = this as Split<T, P>

override fun toString(): String = "Split(df=$df, columns=$columns)"
}

public data class SplitWithTransform<T, C, R>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,16 @@ import kotlin.reflect.KProperty
*
* For more information: {@include [DocumentationUrls.Update]}
*/
public data class Update<T, C>(
val df: DataFrame<T>,
val filter: RowValueFilter<T, C>?,
val columns: ColumnsSelector<T, C>,
public class Update<T, C>(
internal val df: DataFrame<T>,
internal val filter: RowValueFilter<T, C>?,
internal val columns: ColumnsSelector<T, C>,
) {
public fun <R : C> cast(): Update<T, R> =
Update(df, filter as RowValueFilter<T, R>?, columns as ColumnsSelector<T, R>)

override fun toString(): String = "Update(df=$df, filter=$filter, columns=$columns)"

/*
* This argument providing the (clickable) name of the update-like function.
* Note: If clickable, make sure to [alias][your type].
Expand Down Expand Up @@ -188,7 +190,7 @@ public fun <T, C> DataFrame<T>.update(vararg columns: ColumnReference<C>): Updat
* @param [predicate] The [row value filter][RowValueFilter] to select the rows to update.
*/
public fun <T, C> Update<T, C>.where(predicate: RowValueFilter<T, C>): Update<T, C> =
copy(filter = filter and predicate)
Update(df = df, filter = filter and predicate, columns = columns)

/** ## At
* Only update the columns at certain given [row indices][CommonUpdateAtFunctionDoc.RowIndicesParam]:
Expand Down

0 comments on commit 5d88bb2

Please sign in to comment.