Skip to content

Commit 2e55e77

Browse files
KopilovKopilov
authored and
Kopilov
committed
Nullable that does not have nulls. Not nullable that has(!) nulls
1 parent 6bb6cf7 commit 2e55e77

File tree

4 files changed

+26
-2
lines changed
  • core
    • generated-sources/src
    • src

4 files changed

+26
-2
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public interface DataColumn<out T> : BaseColumn<T> {
9797
public fun empty(name: String = ""): AnyCol = createValueColumn(name, emptyList<Unit>(), typeOf<Unit>())
9898
}
9999

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

102102
override fun distinct(): DataColumn<T>
103103

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/contains.kt

+12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import io.kotest.matchers.shouldBe
4+
import org.jetbrains.kotlinx.dataframe.DataColumn
5+
import org.jetbrains.kotlinx.dataframe.hasNulls
46
import org.junit.Test
7+
import kotlin.reflect.full.withNullability
8+
import kotlin.reflect.typeOf
59

610
class ContainsTests {
711

@@ -61,4 +65,12 @@ class ContainsTests {
6165
row.containsKey(b) shouldBe false
6266
row.containsKey(A::b) shouldBe false
6367
}
68+
69+
@Test
70+
fun `nullable vs has nulls`() {
71+
val nullable = DataColumn.create("nullable", listOf("a" as String?, "b" as String?, "c" as String?))
72+
nullable.hasNulls shouldBe false
73+
val notNullable = DataColumn.create("notNullable", listOf("a" as String?, "b" as String?, "c" as String?, null as String?), typeOf<String>().withNullability(false))
74+
notNullable.hasNulls shouldBe true
75+
}
6476
}

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public interface DataColumn<out T> : BaseColumn<T> {
9797
public fun empty(name: String = ""): AnyCol = createValueColumn(name, emptyList<Unit>(), typeOf<Unit>())
9898
}
9999

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

102102
override fun distinct(): DataColumn<T>
103103

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/contains.kt

+12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import io.kotest.matchers.shouldBe
4+
import org.jetbrains.kotlinx.dataframe.DataColumn
5+
import org.jetbrains.kotlinx.dataframe.hasNulls
46
import org.junit.Test
7+
import kotlin.reflect.full.withNullability
8+
import kotlin.reflect.typeOf
59

610
class ContainsTests {
711

@@ -61,4 +65,12 @@ class ContainsTests {
6165
row.containsKey(b) shouldBe false
6266
row.containsKey(A::b) shouldBe false
6367
}
68+
69+
@Test
70+
fun `nullable vs has nulls`() {
71+
val nullable = DataColumn.create("nullable", listOf("a" as String?, "b" as String?, "c" as String?))
72+
nullable.hasNulls shouldBe false
73+
val notNullable = DataColumn.create("notNullable", listOf("a" as String?, "b" as String?, "c" as String?, null as String?), typeOf<String>().withNullability(false))
74+
notNullable.hasNulls shouldBe true
75+
}
6476
}

0 commit comments

Comments
 (0)