@@ -14,9 +14,12 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
14
14
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
15
15
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
16
16
import org.jetbrains.kotlinx.dataframe.columns.asColumnSet
17
+ import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls
17
18
import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarTemplateColumnsSelectionDsl.DslGrammarTemplate
19
+ import org.jetbrains.kotlinx.dataframe.documentation.ExcludeFromSources
18
20
import org.jetbrains.kotlinx.dataframe.documentation.Indent
19
21
import org.jetbrains.kotlinx.dataframe.documentation.LineBreak
22
+ import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
20
23
import org.jetbrains.kotlinx.dataframe.impl.columns.TransformableColumnSet
21
24
import org.jetbrains.kotlinx.dataframe.impl.getTrueIndices
22
25
import org.jetbrains.kotlinx.dataframe.indices
@@ -25,6 +28,12 @@ import kotlin.reflect.KProperty
25
28
26
29
// region DataColumn
27
30
31
+ /* *
32
+ * Returns a new [DataColumn] containing only the elements that match the given [predicate].
33
+ *
34
+ * @param predicate the condition used to filter the elements in the DataColumn.
35
+ * @return a new DataColumn containing elements that satisfy the predicate.
36
+ */
28
37
public inline fun <T > DataColumn<T>.filter (predicate : Predicate <T >): DataColumn <T > =
29
38
indices
30
39
.filter { predicate(get(it)) }
@@ -34,15 +43,88 @@ public inline fun <T> DataColumn<T>.filter(predicate: Predicate<T>): DataColumn<
34
43
35
44
// region DataFrame
36
45
46
+ /* *
47
+ * Filters the rows of this [DataFrame] based on the provided [RowFilter].
48
+ * Returns a new [DataFrame] containing only the rows that satisfy the given [predicate].
49
+ *
50
+ * A [RowFilter] provides each row as a lambda argument, allowing you to define filtering logic
51
+ * using a [Boolean] condition.
52
+ *
53
+ * @include [SelectingColumns.ColumnGroupsAndNestedColumnsMention]
54
+ *
55
+ * For more information, see: {@include [DocumentationUrls.Filter]}
56
+ *
57
+ * See also:
58
+ * - [filterBy], which filters rows based on the values in a given [Boolean] column.
59
+ * - [drop][DataFrame.drop], which drops rows based on values within the row.
60
+ *
61
+ * ### Example
62
+ * ```kotlin
63
+ * // Select rows where the value in the "age" column is greater than 18
64
+ * // and the "name/firstName" column starts with 'A'
65
+ * df.filter { age > 18 && name.firstName.startsWith("A") }
66
+ * ```
67
+ *
68
+ * @param predicate A lambda that takes a row (twice for compatibility) and returns `true`
69
+ * if the row should be included in the result.
70
+ * @return A new [DataFrame] containing only the rows that satisfy the predicate.
71
+ */
37
72
public inline fun <T > DataFrame<T>.filter (predicate : RowFilter <T >): DataFrame <T > =
38
73
indices().filter {
39
74
val row = get(it)
40
75
predicate(row, row)
41
76
}.let { get(it) }
42
77
78
+ /* *
79
+ * Filters the rows of this [DataFrame] based on the [Boolean] values in the specified [column].
80
+ *
81
+ * Returns a new [DataFrame] containing only the rows where the value in the given [column] is `true`.
82
+ *
83
+ * @include [SelectingColumns.ColumnGroupsAndNestedColumnsMention]
84
+ *
85
+ * For more information, see: {@include [DocumentationUrls.Filter]}
86
+ *
87
+ * See also: [filter], which allows filtering rows based on values within the row.
88
+ *
89
+ * ### This Gather Overload
90
+ */
91
+ @ExcludeFromSources
92
+ internal interface FilterByDocs
93
+
94
+ /* *
95
+ * {@include [FilterByDocs]}
96
+ * {@include [SelectingColumns.Dsl]}
97
+ *
98
+ * ### Examples
99
+ * ```kotlin
100
+ * // Filter rows by the "isHappy" column
101
+ * df.filterBy { isHappy }
102
+ *
103
+ * // Filter rows by a single `Boolean` column
104
+ * df.filterBy { colsOf<Boolean>().single() }
105
+ * ```
106
+ *
107
+ * @param column A [ColumnSelector] that selects the Boolean column to use for filtering.
108
+ * Only rows where the value in this column is `true` will be included.
109
+ * @return A new [DataFrame] containing only the rows where the selected column is `true`.
110
+ */
43
111
public fun <T > DataFrame<T>.filterBy (column : ColumnSelector <T , Boolean >): DataFrame <T > =
44
112
getRows(getColumn(column).toList().getTrueIndices())
45
113
114
+ /* *
115
+ * {@include [FilterByDocs]}
116
+ * {@include [SelectingColumns.ColumnNames]}
117
+ *
118
+ * ### Example
119
+ * ```kotlin
120
+ * // Filter rows by the "isHappy" column
121
+ * df.filterBy("isHappy")
122
+ * ```
123
+ *
124
+ * @param column The name of the `Boolean` column to use for filtering.
125
+ * Only rows where the value in this column is `true` will be included.
126
+ * @return A new [DataFrame] containing only the rows where the specified column is `true`.
127
+ */
46
128
public fun <T > DataFrame<T>.filterBy (column : String ): DataFrame <T > = filterBy { column.toColumnOf() }
47
129
48
130
@Deprecated(DEPRECATED_ACCESS_API )
0 commit comments