Skip to content

Commit 355b985

Browse files
adding none to data frame
1 parent 82bf7ba commit 355b985

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import org.jetbrains.kotlinx.dataframe.DataFrame
4+
import org.jetbrains.kotlinx.dataframe.DataRow
5+
import org.jetbrains.kotlinx.dataframe.RowFilter
46
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
57
import org.jetbrains.kotlinx.dataframe.columns.ColumnsResolver
68
import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarTemplateColumnsSelectionDsl.DslGrammarTemplate
@@ -52,3 +54,25 @@ public interface NoneColumnsSelectionDsl {
5254
}
5355

5456
// endregion
57+
58+
// region DataFrame
59+
60+
/**
61+
* Returns `true` if none of the rows in this [DataFrame] satisfies the given [predicate].
62+
*
63+
* {@include [org.jetbrains.kotlinx.dataframe.documentation.RowFilterDescription]}
64+
*
65+
* ### Example
66+
* ```kotlin
67+
* // Check if there is not any row where "age" is greater than 18
68+
* val hasNoAdults = df.none { age > 18 }
69+
* ```
70+
*
71+
* @param predicate A [RowFilter] lambda that takes a [DataRow] (as both `this` and `it`)
72+
* and returns `true` if none of the rows should be considered a match.
73+
* @return `true` if none of the rows satisfies the [predicate], `false` otherwise.
74+
* @see [DataFrame.any]
75+
*/
76+
public inline fun <T> DataFrame<T>.none(predicate: RowFilter<T>): Boolean = rows().none { predicate(it, it) }
77+
78+
// endregion

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/UtilFunctionsTest.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ class UtilFunctionsTest : TestBase() {
2424
df.any { "city"<String?>() == "Berlin" } shouldBe false
2525
}
2626

27+
@Test
28+
fun `DataFrame none`() {
29+
df.none { "age"<Int>() > 40 && "isHappy"<Boolean>() } shouldBe false
30+
df.none { "city"<String?>() == "Berlin" } shouldBe true
31+
}
32+
2733
@Test
2834
fun `DataColumn between`() {
2935
val ages = listOf(15, 45, 20, 40, 30, 20, 30)

0 commit comments

Comments
 (0)