@@ -4,12 +4,16 @@ import io.kotest.matchers.shouldBe
4
4
import kotlinx.datetime.LocalDateTime
5
5
import org.jetbrains.kotlinx.dataframe.DataColumn
6
6
import org.jetbrains.kotlinx.dataframe.DataFrame
7
- import org.jetbrains.kotlinx.dataframe.api.*
7
+ import org.jetbrains.kotlinx.dataframe.api.cast
8
8
import org.jetbrains.kotlinx.dataframe.api.columnOf
9
+ import org.jetbrains.kotlinx.dataframe.api.convertTo
10
+ import org.jetbrains.kotlinx.dataframe.api.parse
11
+ import org.jetbrains.kotlinx.dataframe.api.parser
12
+ import org.jetbrains.kotlinx.dataframe.api.tryParse
9
13
import org.jetbrains.kotlinx.dataframe.exceptions.TypeConversionException
10
14
import org.junit.Test
11
15
import java.math.BigDecimal
12
- import java.util.*
16
+ import java.util.Locale
13
17
import kotlin.reflect.typeOf
14
18
15
19
class ParserTests {
@@ -62,17 +66,27 @@ class ParserTests {
62
66
}
63
67
64
68
@Test
65
- fun `converting string to double in different locales` () {
69
+ fun `convert to Boolean` () {
70
+ val col by columnOf(BigDecimal (1.0 ), BigDecimal (0.0 ), 0 , 1 , 10L , 0.0 , 0.1 )
71
+ col.convertTo<Boolean >().shouldBe(
72
+ DataColumn .createValueColumn(" col" , listOf (true , false , false , true , true , false , true ), typeOf<Boolean >())
73
+ )
74
+ }
75
+
76
+ @Test
77
+ fun `converting String to Double in different locales` () {
66
78
val currentLocale = Locale .getDefault()
67
79
try {
68
80
val stringValues = listOf (" 1" , " 2.3" , " 4,5" )
69
81
val stringColumn = DataColumn .createValueColumn(" nums" , stringValues, typeOf<String >())
70
82
Locale .setDefault(Locale .forLanguageTag(" ru-RU" ))
71
- stringColumn.convertToDouble().shouldBe(
83
+ // Use comma as local decimal separator and dot as fallback default (as it is used in POSIX/C.UTF-8)
84
+ stringColumn.convertTo<Double >().shouldBe(
72
85
DataColumn .createValueColumn(" nums" , listOf (1.0 , 2.3 , 4.5 ), typeOf<Double >())
73
86
)
74
87
Locale .setDefault(Locale .forLanguageTag(" en-US" ))
75
- stringColumn.convertToDouble().shouldBe(
88
+ // Use dot as local decimal separator. Comma is ignored (as it is group separator in this locale).
89
+ stringColumn.convertTo<Double >().shouldBe(
76
90
DataColumn .createValueColumn(" nums" , listOf (1.0 , 2.3 , 45.0 ), typeOf<Double >())
77
91
)
78
92
} finally {
0 commit comments