Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 <init> ()V
}
Expand Down
34 changes: 34 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,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 <T> DataColumn<T>.none(predicate: Predicate<T>): 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 <T> DataFrame<T>.none(predicate: RowFilter<T>): Boolean = rows().none { predicate(it, it) }

// endregion

// region ColumnsSelectionDsl

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,25 @@ class UtilFunctionsTest : TestBase() {
ageCol.any { it > 90 } shouldBe false
}

@Test
fun `DataColumn none`() {
val ageCol = df["age"] as DataColumn<Int>
ageCol.none { it > 40 } shouldBe false
ageCol.none { it > 90 } shouldBe true
}

@Test
fun `DataFrame any`() {
df.any { "age"<Int>() > 40 && "isHappy"<Boolean>() } shouldBe true
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