Skip to content

Commit 9dab767

Browse files
committed
Prepare update and implode operations for compiler plugin support
1 parent 1bb565b commit 9dab767

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ private interface CommonFillNaNsFunctionDoc
203203
* @include [SelectingColumns.Dsl.WithExample] {@include [SetFillNaNsOperationArg]}
204204
* @include [Update.DslParam]
205205
*/
206+
@Interpretable("FillNaNs0")
206207
public fun <T, C> DataFrame<T>.fillNaNs(columns: ColumnsSelector<T, C>): Update<T, C> =
207208
update(columns).where { it.isNaN }
208209

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

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

402406
/**

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ import org.jetbrains.kotlinx.dataframe.ColumnsSelector
44
import org.jetbrains.kotlinx.dataframe.DataFrame
55
import org.jetbrains.kotlinx.dataframe.DataRow
66
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
7+
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
8+
import org.jetbrains.kotlinx.dataframe.annotations.Refine
79
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
810
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
911
import org.jetbrains.kotlinx.dataframe.impl.api.implodeImpl
1012
import kotlin.reflect.KProperty
1113

1214
// region DataFrame
1315

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

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

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public fun <T, C> DataFrame<T>.update(vararg columns: ColumnReference<C>): Updat
206206
*
207207
* @param [predicate] The [row value filter][RowValueFilter] to select the rows to update.
208208
*/
209+
@Interpretable("UpdateWhere")
209210
public fun <T, C> Update<T, C>.where(predicate: RowValueFilter<T, C>): Update<T, C> =
210211
Update(df = df, filter = filter and predicate, columns = columns)
211212

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

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)