Skip to content

Commit 080b507

Browse files
committed
convertToDouble refactor and test
1 parent d0aacfc commit 080b507

File tree

2 files changed

+8
-3
lines changed
  • core/src
    • main/kotlin/org/jetbrains/kotlinx/dataframe/api
    • test/kotlin/org/jetbrains/kotlinx/dataframe/api

2 files changed

+8
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ public fun DataColumn<String?>.convertToDouble(locale: Locale? = null): DataColu
164164
}
165165
}
166166

167-
if (locale != null) {
167+
return if (locale != null) {
168168
val explicitParser = Parsers.getDoubleParser(locale)
169-
return applyParser(explicitParser)
169+
applyParser(explicitParser)
170170
} else {
171-
return try {
171+
try {
172172
val defaultParser = Parsers.getDoubleParser()
173173
applyParser(defaultParser)
174174
} catch (e: TypeConversionException) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.jetbrains.kotlinx.dataframe.exceptions.TypeConverterNotFoundException
1414
import org.jetbrains.kotlinx.dataframe.hasNulls
1515
import org.junit.Test
1616
import java.time.LocalTime
17+
import java.util.*
1718
import kotlin.reflect.*
1819
import kotlin.time.Duration.Companion.hours
1920

@@ -85,6 +86,10 @@ class ConvertTests {
8586
columnOf("1", "10", "a").convertTo<IntClass>()
8687
}.row shouldBe 2
8788

89+
shouldThrow<CellConversionException> {
90+
columnOf("1", "x", "2.5").convertToDouble()
91+
}.row shouldBe 1
92+
8893
shouldThrow<TypeConverterNotFoundException> {
8994
columnOf(EnumClass.A).convertTo<IntClass>()
9095
}

0 commit comments

Comments
 (0)