From 2e55e777994e38fdcac68de92f0f490c5ed646cc Mon Sep 17 00:00:00 2001 From: Kopilov Aleksandr Date: Sat, 22 Jul 2023 10:48:36 +0300 Subject: [PATCH] Nullable that does not have nulls. Not nullable that has(!) nulls --- .../org/jetbrains/kotlinx/dataframe/DataColumn.kt | 2 +- .../org/jetbrains/kotlinx/dataframe/api/contains.kt | 12 ++++++++++++ .../org/jetbrains/kotlinx/dataframe/DataColumn.kt | 2 +- .../org/jetbrains/kotlinx/dataframe/api/contains.kt | 12 ++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt b/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt index 76a752d7fd..722d52da6d 100644 --- a/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt +++ b/core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt @@ -97,7 +97,7 @@ public interface DataColumn : BaseColumn { public fun empty(name: String = ""): AnyCol = createValueColumn(name, emptyList(), typeOf()) } - public fun hasNulls(): Boolean = type().isMarkedNullable + public fun hasNulls(): Boolean = values().any { it == null } override fun distinct(): DataColumn diff --git a/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/contains.kt b/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/contains.kt index 599cf9556d..98fe99b084 100644 --- a/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/contains.kt +++ b/core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/contains.kt @@ -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 { @@ -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().withNullability(false)) + notNullable.hasNulls shouldBe true + } } diff --git a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt index 76a752d7fd..722d52da6d 100644 --- a/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt +++ b/core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt @@ -97,7 +97,7 @@ public interface DataColumn : BaseColumn { public fun empty(name: String = ""): AnyCol = createValueColumn(name, emptyList(), typeOf()) } - public fun hasNulls(): Boolean = type().isMarkedNullable + public fun hasNulls(): Boolean = values().any { it == null } override fun distinct(): DataColumn diff --git a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/contains.kt b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/contains.kt index 599cf9556d..98fe99b084 100644 --- a/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/contains.kt +++ b/core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/contains.kt @@ -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 { @@ -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().withNullability(false)) + notNullable.hasNulls shouldBe true + } }