Skip to content

Commit 3dd1a0d

Browse files
committed
make sure to adjust nullability in order to fix platform types
Platform types can lead to unexpected NPE and the way types rendered now, "URI!" ! sign appears. Code with such type cannot be compiled Given type URI!, type.withNullability will produce either URI or URI?. Both are OK for us.
1 parent 4bb9b15 commit 3dd1a0d

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public fun NullabilityOptions.applyNullability(data: List<Any?>, expectedNulls:
253253

254254
public inline fun <reified T> Iterable<T>.toColumn(
255255
name: String = "",
256-
infer: Infer = Infer.None,
256+
infer: Infer = Infer.Nulls,
257257
): DataColumn<T> =
258258
(
259259
if (infer == Infer.Type) DataColumn.createWithTypeInference(name, asList())
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.jetbrains.kotlinx.dataframe.columns
2+
3+
import io.kotest.matchers.shouldBe
4+
import org.jetbrains.kotlinx.dataframe.api.toColumn
5+
import org.jetbrains.kotlinx.dataframe.api.toDataFrame
6+
import org.junit.Test
7+
import java.net.URI
8+
9+
class DataColumns {
10+
@Test
11+
fun `create column with platform type from Api`() {
12+
val df1 = listOf(1, 2, 3).toDataFrame {
13+
expr { URI.create("http://example.com") } into "text"
14+
}
15+
df1["text"].type().toString() shouldBe "java.net.URI"
16+
}
17+
18+
@Test
19+
fun `create column with nullable platform type from Api`() {
20+
val df1 = listOf(1, 2, 3).toDataFrame {
21+
expr { i -> URI.create("http://example.com").takeIf { i == 2 } } into "text"
22+
}
23+
df1["text"].type().toString() shouldBe "java.net.URI?"
24+
}
25+
26+
@Test
27+
fun `create column with nullable platform type from factory method`() {
28+
val col = listOf(URI.create("http://example.com"), null).toColumn("a")
29+
col.type().toString() shouldBe "java.net.URI?"
30+
}
31+
}

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/TypeConversions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public fun NullabilityOptions.applyNullability(data: List<Any?>, expectedNulls:
253253

254254
public inline fun <reified T> Iterable<T>.toColumn(
255255
name: String = "",
256-
infer: Infer = Infer.None,
256+
infer: Infer = Infer.Nulls,
257257
): DataColumn<T> =
258258
(
259259
if (infer == Infer.Type) DataColumn.createWithTypeInference(name, asList())
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.jetbrains.kotlinx.dataframe.columns
2+
3+
import io.kotest.matchers.shouldBe
4+
import org.jetbrains.kotlinx.dataframe.api.toColumn
5+
import org.jetbrains.kotlinx.dataframe.api.toDataFrame
6+
import org.junit.Test
7+
import java.net.URI
8+
9+
class DataColumns {
10+
@Test
11+
fun `create column with platform type from Api`() {
12+
val df1 = listOf(1, 2, 3).toDataFrame {
13+
expr { URI.create("http://example.com") } into "text"
14+
}
15+
df1["text"].type().toString() shouldBe "java.net.URI"
16+
}
17+
18+
@Test
19+
fun `create column with nullable platform type from Api`() {
20+
val df1 = listOf(1, 2, 3).toDataFrame {
21+
expr { i -> URI.create("http://example.com").takeIf { i == 2 } } into "text"
22+
}
23+
df1["text"].type().toString() shouldBe "java.net.URI?"
24+
}
25+
26+
@Test
27+
fun `create column with nullable platform type from factory method`() {
28+
val col = listOf(URI.create("http://example.com"), null).toColumn("a")
29+
col.type().toString() shouldBe "java.net.URI?"
30+
}
31+
}

0 commit comments

Comments
 (0)