Skip to content

Commit 9ded9e4

Browse files
Automated commit of generated code
1 parent 9da19d0 commit 9ded9e4

File tree

6 files changed

+50
-618
lines changed

6 files changed

+50
-618
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/aliases.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,16 @@ public typealias ColumnsSelector<T, C> = Selector<ColumnsSelectionDsl<T>, Column
137137
// region filters
138138

139139
/**
140-
* ## Row Filter
140+
* A lambda expression that evaluates a row of the [DataFrame]
141+
* and returns a [Boolean] indicating whether the row should be included in the result.
141142
*
142-
* [RowFilter] is a lambda function expecting a [Boolean] result given an instance of [DataRow]`<T>` as context
143-
* (`this` and `it`).
143+
* The lambda has access to the [`DataRow<T>`][DataRow] both as `this` and as `it`,
144+
* enabling concise and readable conditions.
144145
*
145-
* Return `true` if the row should be included in the result.
146+
* Commonly used in operations such as [filter][org.jetbrains.kotlinx.dataframe.api.filter],
147+
* [drop][org.jetbrains.kotlinx.dataframe.api.drop], and others.
146148
*
147-
* Shorthand for:
149+
* Equivalent to:
148150
* ```kotlin
149151
* DataRow<T>.(it: DataRow<T>) -> Boolean
150152
* ```

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/filter.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,18 @@ import org.jetbrains.kotlinx.dataframe.impl.columns.TransformableColumnSet
1818
import org.jetbrains.kotlinx.dataframe.impl.getTrueIndices
1919
import org.jetbrains.kotlinx.dataframe.indices
2020
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
2123
import kotlin.reflect.KProperty
2224

2325
// region DataColumn
2426

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+
*/
2533
public inline fun <T> DataColumn<T>.filter(predicate: Predicate<T>): DataColumn<T> =
2634
indices
2735
.filter { predicate(get(it)) }
@@ -31,21 +39,52 @@ public inline fun <T> DataColumn<T>.filter(predicate: Predicate<T>): DataColumn<
3139

3240
// region DataFrame
3341

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+
*/
3468
public inline fun <T> DataFrame<T>.filter(predicate: RowFilter<T>): DataFrame<T> =
3569
indices().filter {
3670
val row = get(it)
3771
predicate(row, row)
3872
}.let { get(it) }
3973

74+
@Deprecated(message = FILTER_BY, replaceWith = ReplaceWith(FILTER_BY_REPLACE), level = DeprecationLevel.ERROR)
4075
public fun <T> DataFrame<T>.filterBy(column: ColumnSelector<T, Boolean>): DataFrame<T> =
4176
getRows(getColumn(column).toList().getTrueIndices())
4277

78+
@Suppress("DEPRECATION_ERROR")
79+
@Deprecated(message = FILTER_BY, replaceWith = ReplaceWith(FILTER_BY_REPLACE), level = DeprecationLevel.ERROR)
4380
public fun <T> DataFrame<T>.filterBy(column: String): DataFrame<T> = filterBy { column.toColumnOf() }
4481

82+
@Suppress("DEPRECATION_ERROR")
4583
@Deprecated(DEPRECATED_ACCESS_API)
4684
@AccessApiOverload
4785
public fun <T> DataFrame<T>.filterBy(column: ColumnReference<Boolean>): DataFrame<T> = filterBy { column }
4886

87+
@Suppress("DEPRECATION_ERROR")
4988
@Deprecated(DEPRECATED_ACCESS_API)
5089
@AccessApiOverload
5190
public fun <T> DataFrame<T>.filterBy(column: KProperty<Boolean>): DataFrame<T> = filterBy { column.toColumnAccessor() }

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/gather.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public fun <T, C, K, R> Gather<T, C, K, R>.where(filter: RowValueFilter<T, C>):
273273
* Filters out `null` values from the columns previously selected by [gather],
274274
* keeping only non-null entries.
275275
*
276-
* A special case of [where].
276+
* A special case of [Gather.where].
277277
*
278278
* It's an intermediate step; returns a new [Gather] with filtered value columns.
279279
*

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ internal const val CONVERT_TO_URL_REPLACE = "convertToUrl()"
110110
internal const val TO_URL = "This function is replaced by `toUrl()`. $MESSAGE_1_0"
111111
internal const val TO_URL_REPLACE = "toUrl()"
112112

113+
internal const val FILTER_BY = "This function is deprecated in favor of `filter { }`. $MESSAGE_1_0"
114+
internal const val FILTER_BY_REPLACE = "filter { column }"
115+
113116
// endregion
114117

115118
// region WARNING in 1.0, ERROR in 1.1

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Access.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import org.jetbrains.kotlinx.dataframe.api.dropNulls
2020
import org.jetbrains.kotlinx.dataframe.api.dropWhile
2121
import org.jetbrains.kotlinx.dataframe.api.fillNaNs
2222
import org.jetbrains.kotlinx.dataframe.api.filter
23-
import org.jetbrains.kotlinx.dataframe.api.filterBy
2423
import org.jetbrains.kotlinx.dataframe.api.first
2524
import org.jetbrains.kotlinx.dataframe.api.forEach
2625
import org.jetbrains.kotlinx.dataframe.api.gather
@@ -324,22 +323,6 @@ class Access : TestBase() {
324323
// SampleEnd
325324
}
326325

327-
@Test
328-
@TransformDataFrameExpressions
329-
fun filterBy_properties() {
330-
// SampleStart
331-
df.filterBy { isHappy }
332-
// SampleEnd
333-
}
334-
335-
@Test
336-
@TransformDataFrameExpressions
337-
fun filterBy_strings() {
338-
// SampleStart
339-
df.filterBy("isHappy")
340-
// SampleEnd
341-
}
342-
343326
@Test
344327
@TransformDataFrameExpressions
345328
fun dropWhere_properties() {

0 commit comments

Comments
 (0)