@@ -18,10 +18,18 @@ import org.jetbrains.kotlinx.dataframe.impl.columns.TransformableColumnSet
18
18
import org.jetbrains.kotlinx.dataframe.impl.getTrueIndices
19
19
import org.jetbrains.kotlinx.dataframe.indices
20
20
import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
21
+ import org.jetbrains.kotlinx.dataframe.util.FILTER_BY
22
+ import org.jetbrains.kotlinx.dataframe.util.FILTER_BY_REPLACE
21
23
import kotlin.reflect.KProperty
22
24
23
25
// region DataColumn
24
26
27
+ /* *
28
+ * Returns a new [DataColumn] containing only the elements that match the given [predicate].
29
+ *
30
+ * @param predicate the condition used to filter the elements in the DataColumn.
31
+ * @return a new DataColumn containing elements that satisfy the predicate.
32
+ */
25
33
public inline fun <T > DataColumn<T>.filter (predicate : Predicate <T >): DataColumn <T > =
26
34
indices
27
35
.filter { predicate(get(it)) }
@@ -31,21 +39,52 @@ public inline fun <T> DataColumn<T>.filter(predicate: Predicate<T>): DataColumn<
31
39
32
40
// region DataFrame
33
41
42
+ /* *
43
+ * Filters the rows of this [DataFrame] based on the provided [RowFilter].
44
+ * Returns a new [DataFrame] containing only the rows that satisfy the given [predicate].
45
+ *
46
+ * A [RowFilter] provides each row as a lambda argument, allowing you to define filtering logic
47
+ * using a [Boolean] condition.
48
+ *
49
+ * This can include [column groups][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] and nested columns.
50
+ *
51
+ * For more information, see: [See `filter` on the documentation website.](https://kotlin.github.io/dataframe/filter.html)
52
+ *
53
+ * See also:
54
+ * - [drop][DataFrame.drop], which drops rows based on values within the row.
55
+ * - [distinct][DataFrame.distinct], which filters out rows with duplicated values.
56
+ *
57
+ * ### Example
58
+ * ```kotlin
59
+ * // Select rows where the value in the "age" column is greater than 18
60
+ * // and the "name/firstName" column starts with 'A'
61
+ * df.filter { age > 18 && name.firstName.startsWith("A") }
62
+ * ```
63
+ *
64
+ * @param predicate A lambda that takes a row (twice for compatibility) and returns `true`
65
+ * if the row should be included in the result.
66
+ * @return A new [DataFrame] containing only the rows that satisfy the predicate.
67
+ */
34
68
public inline fun <T > DataFrame<T>.filter (predicate : RowFilter <T >): DataFrame <T > =
35
69
indices().filter {
36
70
val row = get(it)
37
71
predicate(row, row)
38
72
}.let { get(it) }
39
73
74
+ @Deprecated(message = FILTER_BY , replaceWith = ReplaceWith (FILTER_BY_REPLACE ), level = DeprecationLevel .ERROR )
40
75
public fun <T > DataFrame<T>.filterBy (column : ColumnSelector <T , Boolean >): DataFrame <T > =
41
76
getRows(getColumn(column).toList().getTrueIndices())
42
77
78
+ @Suppress(" DEPRECATION_ERROR" )
79
+ @Deprecated(message = FILTER_BY , replaceWith = ReplaceWith (FILTER_BY_REPLACE ), level = DeprecationLevel .ERROR )
43
80
public fun <T > DataFrame<T>.filterBy (column : String ): DataFrame <T > = filterBy { column.toColumnOf() }
44
81
82
+ @Suppress(" DEPRECATION_ERROR" )
45
83
@Deprecated(DEPRECATED_ACCESS_API )
46
84
@AccessApiOverload
47
85
public fun <T > DataFrame<T>.filterBy (column : ColumnReference <Boolean >): DataFrame <T > = filterBy { column }
48
86
87
+ @Suppress(" DEPRECATION_ERROR" )
49
88
@Deprecated(DEPRECATED_ACCESS_API )
50
89
@AccessApiOverload
51
90
public fun <T > DataFrame<T>.filterBy (column : KProperty <Boolean >): DataFrame <T > = filterBy { column.toColumnAccessor() }
0 commit comments