@@ -3,6 +3,7 @@ package org.jetbrains.kotlinx.dataframe.api
3
3
import io.kotest.assertions.throwables.shouldNotThrow
4
4
import io.kotest.assertions.throwables.shouldThrow
5
5
import io.kotest.matchers.shouldBe
6
+ import io.kotest.matchers.shouldNotBe
6
7
import kotlinx.datetime.Clock
7
8
import kotlinx.datetime.Instant
8
9
import kotlinx.datetime.LocalTime
@@ -69,6 +70,20 @@ class ConvertTests {
69
70
@Test
70
71
fun `convert string to enum` () {
71
72
columnOf(" A" , " B" ).convertTo<EnumClass >() shouldBe columnOf(EnumClass .A , EnumClass .B )
73
+
74
+ dataFrameOf(columnOf(" A" , " B" ) named " colA" )
75
+ .convert(" colA" ).to<EnumClass >()
76
+ .getColumn(" colA" ) shouldBe columnOf(EnumClass .A , EnumClass .B ).named(" colA" )
77
+ }
78
+
79
+ @Test
80
+ fun `convert char to enum` () {
81
+ // Char -> String -> Enum
82
+ columnOf(' A' , ' B' ).convertTo<EnumClass >() shouldBe columnOf(EnumClass .A , EnumClass .B )
83
+
84
+ dataFrameOf(columnOf(' A' , ' B' ) named " colA" )
85
+ .convert(" colA" ).to<EnumClass >()
86
+ .getColumn(" colA" ) shouldBe columnOf(EnumClass .A , EnumClass .B ).named(" colA" )
72
87
}
73
88
74
89
@JvmInline
@@ -199,6 +214,13 @@ class ConvertTests {
199
214
val col = columnOf(65 , 66 )
200
215
col.convertTo<Char >() shouldBe columnOf(' A' , ' B' )
201
216
col.convertTo<Char >().convertTo<Int >() shouldBe col
217
+
218
+ // this means
219
+ columnOf(' 1' , ' 2' ).convertToInt() shouldNotBe columnOf(1 , 2 )
220
+ columnOf(' 1' , ' 2' ).convertToInt() shouldBe columnOf(49 , 50 )
221
+
222
+ // but
223
+ columnOf(' 1' , ' 2' ).convertToString().convertToInt() shouldBe columnOf(1 , 2 )
202
224
}
203
225
204
226
@Test
0 commit comments