Skip to content

Commit a1b99f3

Browse files
deprecate candidates for removal
1 parent bef0c40 commit a1b99f3

File tree

8 files changed

+34
-42
lines changed

8 files changed

+34
-42
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/annotations/CandidateForRemoval.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.

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

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
88
import org.jetbrains.kotlinx.dataframe.DataRow
99
import org.jetbrains.kotlinx.dataframe.RowExpression
1010
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
11-
import org.jetbrains.kotlinx.dataframe.annotations.CandidateForRemoval
1211
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
1312
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
1413
import org.jetbrains.kotlinx.dataframe.impl.columnName
@@ -18,14 +17,16 @@ import org.jetbrains.kotlinx.dataframe.indices
1817
import org.jetbrains.kotlinx.dataframe.ncol
1918
import org.jetbrains.kotlinx.dataframe.nrow
2019
import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
20+
import org.jetbrains.kotlinx.dataframe.util.MESSAGE_SHORTCUT_1_0
2121
import kotlin.experimental.ExperimentalTypeInference
2222
import kotlin.reflect.KProperty
2323
import kotlin.reflect.KType
2424

25-
@CandidateForRemoval
25+
@Deprecated(MESSAGE_SHORTCUT_1_0, ReplaceWith("values().all { it == null }"), DeprecationLevel.ERROR)
2626
public fun AnyRow.isEmpty(): Boolean = owner.columns().all { it[index] == null }
2727

28-
@CandidateForRemoval
28+
@Suppress("DEPRECATION_ERROR")
29+
@Deprecated(MESSAGE_SHORTCUT_1_0, ReplaceWith("values().any { it != null }"), DeprecationLevel.ERROR)
2930
public fun AnyRow.isNotEmpty(): Boolean = !isEmpty()
3031

3132
public inline fun <reified R> AnyRow.valuesOf(): List<R> = values().filterIsInstance<R>()
@@ -178,35 +179,50 @@ public fun AnyRow.columnNames(): List<String> = df().columnNames()
178179

179180
public fun AnyRow.columnTypes(): List<KType> = df().columnTypes()
180181

181-
@CandidateForRemoval
182+
@Suppress("DEPRECATION_ERROR")
183+
@Deprecated(MESSAGE_SHORTCUT_1_0, ReplaceWith("df().getRow(index)"), DeprecationLevel.ERROR)
182184
public fun <T> DataRow<T>.getRow(index: Int): DataRow<T> = getRowOrNull(index)!!
183185

184-
@CandidateForRemoval
186+
@Deprecated(MESSAGE_SHORTCUT_1_0, ReplaceWith("df().getRows(indices)"), DeprecationLevel.ERROR)
185187
public fun <T> DataRow<T>.getRows(indices: Iterable<Int>): DataFrame<T> = df().getRows(indices)
186188

187-
@CandidateForRemoval
189+
@Deprecated(MESSAGE_SHORTCUT_1_0, ReplaceWith("df().getRows(indices)"), DeprecationLevel.ERROR)
188190
public fun <T> DataRow<T>.getRows(indices: IntRange): DataFrame<T> = df().getRows(indices)
189191

190-
@CandidateForRemoval
192+
@Deprecated(MESSAGE_SHORTCUT_1_0, ReplaceWith("df().getRowOrNull(index)"), DeprecationLevel.ERROR)
191193
public fun <T> DataRow<T>.getRowOrNull(index: Int): DataRow<T>? {
192194
val df = df()
193195
return if (index >= 0 && index < df.nrow) df[index] else null
194196
}
195197

198+
/**
199+
* Returns the previous [row][DataRow] in the [DataFrame] relative to the current row.
200+
* If the current row is the first row in the [DataFrame], it returns `null`.
201+
*
202+
* @return The previous [DataRow] if it exists, or `null` if the current row is the first in the [DataFrame].
203+
*/
196204
public fun <T> DataRow<T>.prev(): DataRow<T>? {
197205
val index = index()
198206
return if (index > 0) df()[index - 1] else null
199207
}
200208

209+
/**
210+
* Returns the next [row][DataRow] in the [DataFrame] relative to the current row.
211+
* If the current row is the last row in the [DataFrame], it returns `null`.
212+
*
213+
* @return The previous [DataRow] if it exists, or `null` if the current row is the last in the [DataFrame].
214+
*/
201215
public fun <T> DataRow<T>.next(): DataRow<T>? {
202216
val index = index()
203217
val df = df()
204218
return if (index < df.nrow - 1) df[index + 1] else null
205219
}
206220

221+
@Suppress("DEPRECATION_ERROR")
207222
public fun <T> DataRow<T>.relative(relativeIndices: Iterable<Int>): DataFrame<T> =
208223
getRows(relativeIndices.mapNotNull { (index + it).let { if (it >= 0 && it < df().rowsCount()) it else null } })
209224

225+
@Suppress("DEPRECATION_ERROR")
210226
public fun <T> DataRow<T>.relative(relativeIndices: IntRange): DataFrame<T> =
211227
getRows(
212228
(relativeIndices.first + index).coerceIn(df().indices)..(relativeIndices.last + index).coerceIn(df().indices),
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import org.jetbrains.kotlinx.dataframe.DataFrame
4-
import org.jetbrains.kotlinx.dataframe.annotations.CandidateForRemoval
4+
import org.jetbrains.kotlinx.dataframe.util.MESSAGE_SHORTCUT_1_0
5+
56
// region DataFrame
67

7-
@CandidateForRemoval
8+
@Deprecated(MESSAGE_SHORTCUT_1_0, ReplaceWith("columns().toDataFrame().cast()"), DeprecationLevel.ERROR)
89
public fun <T> DataFrame<T>.copy(): DataFrame<T> = columns().toDataFrame().cast()
910

1011
// endregion

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public fun <T, C, R> Merge<T, C, R>.intoList(): List<R> =
9090
public fun <T, C, R> MergeWithTransform<T, C, R>.intoList(): List<R> =
9191
df.select(selector).rows().map { transform(it, it.values() as List<C>) }
9292

93+
@Suppress("DEPRECATION_ERROR")
9394
public fun <T, C, R> MergeWithTransform<T, C, R>.into(path: ColumnPath): DataFrame<T> {
9495
// If target path exists, merge into temp path
9596
val mergePath = if (df.getColumnOrNull(path) != null) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import org.jetbrains.kotlinx.dataframe.ColumnSelector
66
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
77
import org.jetbrains.kotlinx.dataframe.DataFrame
88
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
9-
import org.jetbrains.kotlinx.dataframe.annotations.CandidateForRemoval
109
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
1110
import org.jetbrains.kotlinx.dataframe.annotations.Refine
1211
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
@@ -24,6 +23,7 @@ import org.jetbrains.kotlinx.dataframe.impl.api.moveImpl
2423
import org.jetbrains.kotlinx.dataframe.impl.api.moveTo
2524
import org.jetbrains.kotlinx.dataframe.ncol
2625
import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
26+
import org.jetbrains.kotlinx.dataframe.util.MESSAGE_SHORTCUT_1_0
2727
import org.jetbrains.kotlinx.dataframe.util.MOVE_TO_LEFT
2828
import org.jetbrains.kotlinx.dataframe.util.MOVE_TO_LEFT_REPLACE
2929
import org.jetbrains.kotlinx.dataframe.util.MOVE_TO_RIGHT
@@ -409,7 +409,7 @@ public fun <T, C> MoveClause<T, C>.into(
409409
/**
410410
* Move a single selected column to top level with a new name
411411
*/
412-
@CandidateForRemoval
412+
@Deprecated(MESSAGE_SHORTCUT_1_0, ReplaceWith("into { pathOf(column) }"), DeprecationLevel.ERROR)
413413
@Refine
414414
@Interpretable("MoveInto0")
415415
public fun <T, C> MoveClause<T, C>.into(column: String): DataFrame<T> = pathOf(column).let { path -> into { path } }

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/aggregation/modes/aggregateBy.kt

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,15 @@ package org.jetbrains.kotlinx.dataframe.impl.aggregation.modes
22

33
import org.jetbrains.kotlinx.dataframe.DataColumn
44
import org.jetbrains.kotlinx.dataframe.DataFrame
5-
import org.jetbrains.kotlinx.dataframe.DataFrameExpression
65
import org.jetbrains.kotlinx.dataframe.DataRow
76
import org.jetbrains.kotlinx.dataframe.RowExpression
8-
import org.jetbrains.kotlinx.dataframe.annotations.CandidateForRemoval
9-
import org.jetbrains.kotlinx.dataframe.api.GroupBy
10-
import org.jetbrains.kotlinx.dataframe.api.Grouped
117
import org.jetbrains.kotlinx.dataframe.api.asSequence
12-
import org.jetbrains.kotlinx.dataframe.api.cast
138
import org.jetbrains.kotlinx.dataframe.api.getOrNull
149
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
15-
import org.jetbrains.kotlinx.dataframe.impl.aggregation.aggregateInternal
1610
import org.jetbrains.kotlinx.dataframe.impl.aggregation.aggregators.Aggregator
1711
import org.jetbrains.kotlinx.dataframe.impl.aggregation.aggregators.indexOfAggregationResult
18-
import org.jetbrains.kotlinx.dataframe.impl.namedValues
1912
import kotlin.reflect.typeOf
2013

21-
@CandidateForRemoval
22-
internal fun <T> Grouped<T>.aggregateByOrNull(body: DataFrameExpression<T, DataRow<T>?>): DataFrame<T> {
23-
require(this is GroupBy<*, T>)
24-
val keyColumns = keys.columnNames().toSet()
25-
return aggregateInternal {
26-
val row = body(df, df)
27-
row?.namedValues()?.forEach {
28-
if (!keyColumns.contains(it.name)) yield(it)
29-
}
30-
}.cast()
31-
}
32-
3314
/**
3415
* Selects the best matching value in the [sequence][values]
3516
* using the provided [Aggregator] `by` the provided [selector].

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ internal const val INSERT_AFTER_COL_PATH =
143143
"This `after()` overload will be removed in favor of `after { }` with Column Selection DSL. $MESSAGE_1_0"
144144
internal const val INSERT_AFTER_COL_PATH_REPLACE = "this.after { columnPath }"
145145

146+
internal const val MESSAGE_SHORTCUT_1_0 = "This shortcut is deprecated. $MESSAGE_1_0"
147+
146148
// endregion
147149

148150
// region WARNING in 1.0, ERROR in 1.1

dataframe-arrow/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/ArrowKtTest.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ internal class ArrowKtTest {
354354

355355
@Test
356356
fun testNarrowing() {
357-
val frameWithoutRequiredField = citiesExampleFrame.copy().remove("settled")
357+
val frameWithoutRequiredField = citiesExampleFrame.remove("settled")
358358

359359
frameWithoutRequiredField.arrowWriter(
360360
targetSchema = Schema.fromJSON(citiesExampleSchema),
@@ -381,7 +381,7 @@ internal class ArrowKtTest {
381381

382382
@Test
383383
fun testStrictType() {
384-
val frameRenaming = citiesExampleFrame.copy().remove("settled")
384+
val frameRenaming = citiesExampleFrame.remove("settled")
385385
val frameWithIncompatibleField =
386386
frameRenaming.add(
387387
frameRenaming["is_capital"]
@@ -424,7 +424,7 @@ internal class ArrowKtTest {
424424

425425
@Test
426426
fun testStrictNullable() {
427-
val frameRenaming = citiesExampleFrame.copy().remove("settled")
427+
val frameRenaming = citiesExampleFrame.remove("settled")
428428
val frameWithNulls = frameRenaming.add(
429429
DataColumn.createValueColumn(
430430
"settled",

0 commit comments

Comments
 (0)