Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/none.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.jetbrains.kotlinx.dataframe.api

import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.RowFilter
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
import org.jetbrains.kotlinx.dataframe.columns.ColumnsResolver
import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarTemplateColumnsSelectionDsl.DslGrammarTemplate
Expand Down Expand Up @@ -52,3 +54,25 @@ public interface NoneColumnsSelectionDsl {
}

// endregion

// region DataFrame

/**
* Returns `true` if none of the rows in this [DataFrame] satisfies the given [predicate].
*
* {@include [org.jetbrains.kotlinx.dataframe.documentation.RowFilterDescription]}
*
* ### Example
* ```kotlin
* // Check if there is not any row where "age" is greater than 18
* val hasNoAdults = df.none { age > 18 }
* ```
*
* @param predicate A [RowFilter] lambda that takes a [DataRow] (as both `this` and `it`)
* and returns `true` if none of the rows should be considered a match.
* @return `true` if none of the rows satisfies the [predicate], `false` otherwise.
* @see [DataFrame.any]
*/
public inline fun <T> DataFrame<T>.none(predicate: RowFilter<T>): Boolean = rows().none { predicate(it, it) }

// endregion
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class UtilFunctionsTest : TestBase() {
df.any { "city"<String?>() == "Berlin" } shouldBe false
}

@Test
fun `DataFrame none`() {
df.none { "age"<Int>() > 40 && "isHappy"<Boolean>() } shouldBe false
df.none { "city"<String?>() == "Berlin" } shouldBe true
}

@Test
fun `DataColumn between`() {
val ages = listOf(15, 45, 20, 40, 30, 20, 30)
Expand Down
Loading