diff --git a/core/api/core.api b/core/api/core.api index 283e186f54..8c2b056804 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -3471,6 +3471,11 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/api/NoneColumnsS public abstract interface class org/jetbrains/kotlinx/dataframe/api/NoneColumnsSelectionDsl$Grammar$PlainDslName { } +public final class org/jetbrains/kotlinx/dataframe/api/NoneKt { + public static final fun none (Lorg/jetbrains/kotlinx/dataframe/DataColumn;Lkotlin/jvm/functions/Function1;)Z + public static final fun none (Lorg/jetbrains/kotlinx/dataframe/DataFrame;Lkotlin/jvm/functions/Function2;)Z +} + public final class org/jetbrains/kotlinx/dataframe/api/NullabilityException : java/lang/Exception { public fun ()V } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/none.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/none.kt index 828e3c7c89..29c32bb6ca 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/none.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/none.kt @@ -1,11 +1,45 @@ package org.jetbrains.kotlinx.dataframe.api +import org.jetbrains.kotlinx.dataframe.DataColumn import org.jetbrains.kotlinx.dataframe.DataFrame +import org.jetbrains.kotlinx.dataframe.DataRow +import org.jetbrains.kotlinx.dataframe.Predicate +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.columns.values import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarTemplateColumnsSelectionDsl.DslGrammarTemplate import org.jetbrains.kotlinx.dataframe.impl.columns.ColumnListImpl +// region DataColumn + +/** Returns `true` if none of the [values] match the given [predicate] */ +public fun DataColumn.none(predicate: Predicate): Boolean = values.none(predicate) + +// 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 DataFrame.none(predicate: RowFilter): Boolean = rows().none { predicate(it, it) } + +// endregion + // region ColumnsSelectionDsl /** diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/UtilFunctionsTest.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/UtilFunctionsTest.kt index a29c37dffd..7b8e2ea174 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/UtilFunctionsTest.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/UtilFunctionsTest.kt @@ -18,12 +18,25 @@ class UtilFunctionsTest : TestBase() { ageCol.any { it > 90 } shouldBe false } + @Test + fun `DataColumn none`() { + val ageCol = df["age"] as DataColumn + ageCol.none { it > 40 } shouldBe false + ageCol.none { it > 90 } shouldBe true + } + @Test fun `DataFrame any`() { df.any { "age"() > 40 && "isHappy"() } shouldBe true df.any { "city"() == "Berlin" } shouldBe false } + @Test + fun `DataFrame none`() { + df.none { "age"() > 40 && "isHappy"() } shouldBe false + df.none { "city"() == "Berlin" } shouldBe true + } + @Test fun `DataColumn between`() { val ages = listOf(15, 45, 20, 40, 30, 20, 30)