Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ private interface CommonFillNaNsFunctionDoc
* @include [SelectingColumns.Dsl.WithExample] {@include [SetFillNaNsOperationArg]}
* @include [Update.DslParam]
*/
@Interpretable("FillNaNs0")
public fun <T, C> DataFrame<T>.fillNaNs(columns: ColumnsSelector<T, C>): Update<T, C> =
update(columns).where { it.isNaN }

Expand Down Expand Up @@ -281,6 +282,7 @@ private interface CommonFillNAFunctionDoc
* @include [SelectingColumns.Dsl.WithExample] {@include [SetFillNAOperationArg]}
* @include [Update.DslParam]
*/
@Interpretable("FillNulls0") // fillNA changes schema same as fillNulls
public fun <T, C> DataFrame<T>.fillNA(columns: ColumnsSelector<T, C?>): Update<T, C?> =
update(columns).where { it.isNA }

Expand Down Expand Up @@ -397,6 +399,8 @@ public fun <T> DataFrame<T>.dropNulls(whereAllNull: Boolean = false, columns: Co
* This overload operates on all columns in the [DataFrame].
* @include [DropNulls.WhereAllNullParam]
*/
@Refine
@Interpretable("DropNulls1")
public fun <T> DataFrame<T>.dropNulls(whereAllNull: Boolean = false): DataFrame<T> = dropNulls(whereAllNull) { all() }

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import org.jetbrains.kotlinx.dataframe.ColumnsSelector
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
import org.jetbrains.kotlinx.dataframe.annotations.Refine
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.impl.api.implodeImpl
import kotlin.reflect.KProperty

// region DataFrame

@Refine
@Interpretable("ImplodeDefault")
public fun <T> DataFrame<T>.implode(dropNA: Boolean = false): DataRow<T> = implode(dropNA) { all() }[0]

@Refine
@Interpretable("Implode")
public fun <T, C> DataFrame<T>.implode(dropNA: Boolean = false, columns: ColumnsSelector<T, C>): DataFrame<T> =
implodeImpl(dropNA, columns)

Expand Down
10 changes: 10 additions & 0 deletions core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/update.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,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.
*/
@Interpretable("UpdateWhere")
public fun <T, C> Update<T, C>.where(predicate: RowValueFilter<T, C>): Update<T, C> =
Update(df = df, filter = filter and predicate, columns = columns)

Expand Down Expand Up @@ -236,6 +237,7 @@ private interface CommonUpdateAtFunctionDoc {
*
* @param [rowIndices] {@include [CommonUpdateAtFunctionDoc.RowIndicesParam]}
*/
@Interpretable("UpdateAt")
public fun <T, C> Update<T, C>.at(rowIndices: Collection<Int>): Update<T, C> = where { index in rowIndices }

/**
Expand All @@ -245,6 +247,7 @@ public fun <T, C> Update<T, C>.at(rowIndices: Collection<Int>): Update<T, C> = w
*
* @param [rowIndices] {@include [CommonUpdateAtFunctionDoc.RowIndicesParam]}
*/
@Interpretable("UpdateAt")
public fun <T, C> Update<T, C>.at(vararg rowIndices: Int): Update<T, C> = at(rowIndices.toSet())

/**
Expand All @@ -254,6 +257,7 @@ public fun <T, C> Update<T, C>.at(vararg rowIndices: Int): Update<T, C> = at(row
*
* @param [rowRange] {@include [CommonUpdateAtFunctionDoc.RowIndicesParam]}
*/
@Interpretable("UpdateAt")
public fun <T, C> Update<T, C>.at(rowRange: IntRange): Update<T, C> = where { index in rowRange }

/** ## Per Row Col
Expand All @@ -265,6 +269,7 @@ public fun <T, C> Update<T, C>.at(rowRange: IntRange): Update<T, C> = where { in
* - {@include [SeeAlsoUpdatePerCol]}
* @param [expression] The {@include [ExpressionsGivenRowAndColumn.RowColumnExpressionLink]} to provide a new value for every selected cell giving its row and column.
*/
@Interpretable("UpdatePerRowCol")
public inline fun <T, C> Update<T, C>.perRowCol(crossinline expression: RowColumnExpression<T, C, C>): DataFrame<T> =
updateImpl { row, column, _ -> expression(row, column) }

Expand Down Expand Up @@ -354,6 +359,7 @@ private interface CommonUpdatePerColMapDoc
* @param [values] The [Map]<[String], Value> to provide a new value for every selected cell.
* For each selected column, there must be a value in the map with the same name.
*/
@Interpretable("UpdatePerColMap")
public fun <T, C> Update<T, C>.perCol(values: Map<String, C>): DataFrame<T> =
updateWithValuePerColumnImpl {
values[it.name()] ?: throw IllegalArgumentException("Update value for column ${it.name()} is not defined")
Expand All @@ -371,6 +377,7 @@ public fun <T, C> Update<T, C>.perCol(values: Map<String, C>): DataFrame<T> =
*
* @param [values] The [DataRow] to provide a new value for every selected cell.
*/
@Interpretable("UpdatePerColRow")
public fun <T, C> Update<T, C>.perCol(values: AnyRow): DataFrame<T> = perCol(values.toMap() as Map<String, C>)

/**
Expand All @@ -380,6 +387,7 @@ public fun <T, C> Update<T, C>.perCol(values: AnyRow): DataFrame<T> = perCol(val
*
* @param [valueSelector] The {@include [ExpressionsGivenColumn.ColumnExpressionLink]} to provide a new value for every selected cell giving its column.
*/
@Interpretable("UpdatePerCol")
public fun <T, C> Update<T, C>.perCol(valueSelector: ColumnExpression<C, C>): DataFrame<T> =
updateWithValuePerColumnImpl(valueSelector)

Expand All @@ -395,6 +403,7 @@ internal infix fun <T, C> RowValueFilter<T, C>?.and(other: RowValueFilter<T, C>)
}

/** @include [Update.notNull] */
@Interpretable("UpdateNotNullDefault")
public fun <T, C> Update<T, C?>.notNull(): Update<T, C> = where { it != null } as Update<T, C>

/**
Expand All @@ -418,6 +427,7 @@ public fun <T, C> Update<T, C?>.notNull(): Update<T, C> = where { it != null } a
* {@comment No brackets around `expression` because this doc is copied to [Update.notNull]}
* @param expression Optional {@include [ExpressionsGivenRow.RowExpressionLink]} to update the rows with.
*/
@Interpretable("UpdateNotNull")
public fun <T, C> Update<T, C?>.notNull(expression: UpdateExpression<T, C, C>): DataFrame<T> =
notNull().with(expression)

Expand Down
Loading