Skip to content

Commit

Permalink
Nullable that does not have nulls. Not nullable that has(!) nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
Kopilov committed Jul 22, 2023
1 parent 5488a34 commit af06594
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public interface DataColumn<out T> : BaseColumn<T> {
public fun empty(name: String = ""): AnyCol = createValueColumn(name, emptyList<Unit>(), typeOf<Unit>())
}

public fun hasNulls(): Boolean = type().isMarkedNullable
public fun hasNulls(): Boolean = values().any { it == null }

override fun distinct(): DataColumn<T>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.jetbrains.kotlinx.dataframe.api

import io.kotest.matchers.shouldBe
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.hasNulls
import org.junit.Test
import kotlin.reflect.full.withNullability
import kotlin.reflect.typeOf

class ContainsTests {

Expand Down Expand Up @@ -61,4 +65,12 @@ class ContainsTests {
row.containsKey(b) shouldBe false
row.containsKey(A::b) shouldBe false
}

@Test
fun `nullable vs has nulls`() {
val nullable = DataColumn.create("nullable", listOf("a" as String?, "b" as String?, "c" as String?))
nullable.hasNulls shouldBe false
val notNullable = DataColumn.create("notNullable", listOf("a" as String?, "b" as String?, "c" as String?, null as String?), typeOf<String>().withNullability(false))
notNullable.hasNulls shouldBe true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public interface DataColumn<out T> : BaseColumn<T> {
public fun empty(name: String = ""): AnyCol = createValueColumn(name, emptyList<Unit>(), typeOf<Unit>())
}

public fun hasNulls(): Boolean = type().isMarkedNullable
public fun hasNulls(): Boolean = values().any { it == null }

override fun distinct(): DataColumn<T>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.jetbrains.kotlinx.dataframe.api

import io.kotest.matchers.shouldBe
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.hasNulls
import org.junit.Test
import kotlin.reflect.full.withNullability
import kotlin.reflect.typeOf

class ContainsTests {

Expand Down Expand Up @@ -61,4 +65,12 @@ class ContainsTests {
row.containsKey(b) shouldBe false
row.containsKey(A::b) shouldBe false
}

@Test
fun `nullable vs has nulls`() {
val nullable = DataColumn.create("nullable", listOf("a" as String?, "b" as String?, "c" as String?))
nullable.hasNulls shouldBe false
val notNullable = DataColumn.create("notNullable", listOf("a" as String?, "b" as String?, "c" as String?, null as String?), typeOf<String>().withNullability(false))
notNullable.hasNulls shouldBe true
}
}

0 comments on commit af06594

Please sign in to comment.