Skip to content

Commit 6f28237

Browse files
authored
Merge pull request #1040 from Kotlin/stabilize-fast-double-parser
Stabilize FastDoubleParser part 1
2 parents 90d8153 + 08570f9 commit 6f28237

File tree

9 files changed

+469
-122
lines changed

9 files changed

+469
-122
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import org.jetbrains.kotlinx.dataframe.impl.api.toLocalDateTime
3636
import org.jetbrains.kotlinx.dataframe.impl.api.toLocalTime
3737
import org.jetbrains.kotlinx.dataframe.impl.api.withRowCellImpl
3838
import org.jetbrains.kotlinx.dataframe.impl.headPlusArray
39+
import org.jetbrains.kotlinx.dataframe.impl.io.FastDoubleParser
3940
import org.jetbrains.kotlinx.dataframe.io.toDataFrame
4041
import java.math.BigDecimal
4142
import java.math.BigInteger
@@ -226,8 +227,8 @@ public fun DataColumn<String>.convertToDouble(locale: Locale? = null): DataColum
226227
* @include [DataColumnStringConvertToDoubleDoc]
227228
* @param nullStrings a set of strings that should be treated as `null` values.
228229
* The default in [DataFrame.parser][DataFrame.Companion.parser] is ["null", "NULL", "NA", "N/A"].
229-
* @param useFastDoubleParser whether to use the new _experimental_ FastDoubleParser.
230-
* The default in [DataFrame.parser][DataFrame.Companion.parser] is `false` for now.
230+
* @param useFastDoubleParser whether to use [FastDoubleParser].
231+
* The default in [DataFrame.parser][DataFrame.Companion.parser] is `true`.
231232
*/
232233
@JvmName("convertToDoubleFromString")
233234
public fun DataColumn<String>.convertToDouble(
@@ -246,8 +247,8 @@ public fun DataColumn<String?>.convertToDouble(locale: Locale? = null): DataColu
246247
* @include [DataColumnStringConvertToDoubleDoc]
247248
* @param nullStrings a set of strings that should be treated as `null` values.
248249
* The default in [DataFrame.parser][DataFrame.Companion.parser] is ["null", "NULL", "NA", "N/A"].
249-
* @param useFastDoubleParser whether to use the new _experimental_ FastDoubleParser.
250-
* The default in [DataFrame.parser][DataFrame.Companion.parser] is `false` for now.
250+
* @param useFastDoubleParser whether to use [FastDoubleParser].
251+
* The default in [DataFrame.parser][DataFrame.Companion.parser] is `true`.
251252
*/
252253
@JvmName("convertToDoubleFromStringNullable")
253254
public fun DataColumn<String?>.convertToDouble(

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.jetbrains.kotlinx.dataframe.impl.api.Parsers
1111
import org.jetbrains.kotlinx.dataframe.impl.api.StringParser
1212
import org.jetbrains.kotlinx.dataframe.impl.api.parseImpl
1313
import org.jetbrains.kotlinx.dataframe.impl.api.tryParseImpl
14+
import org.jetbrains.kotlinx.dataframe.impl.io.FastDoubleParser
1415
import org.jetbrains.kotlinx.dataframe.io.readCSV
1516
import org.jetbrains.kotlinx.dataframe.typeClass
1617
import org.jetbrains.kotlinx.dataframe.util.PARSER_OPTIONS
@@ -45,6 +46,12 @@ public fun <T, C> DataFrame<T>.parse(vararg columns: ColumnReference<C>, options
4546
public fun <T, C> DataFrame<T>.parse(vararg columns: KProperty<C>, options: ParserOptions? = null): DataFrame<T> =
4647
parse(options) { columns.toColumnSet() }
4748

49+
/**
50+
* Global counterpart of [ParserOptions].
51+
* Settings changed here will affect the defaults for all parsing operations.
52+
*
53+
* The default values are set by [Parsers.resetToDefault].
54+
*/
4855
public interface GlobalParserOptions {
4956

5057
public fun addDateTimePattern(pattern: String)
@@ -54,7 +61,7 @@ public interface GlobalParserOptions {
5461
/** This function can be called to skip some types. Parsing will be attempted for all other types. */
5562
public fun addSkipType(type: KType)
5663

57-
/** Whether to use the new _experimental_ FastDoubleParser, defaults to `false` for now. */
64+
/** Whether to use [FastDoubleParser], defaults to `true`. Please report any issues you encounter. */
5865
public var useFastDoubleParser: Boolean
5966

6067
public fun resetToDefault()
@@ -91,7 +98,7 @@ public interface GlobalParserOptions {
9198
* `["null", "NULL", "NA", "N/A"]`.
9299
* @param skipTypes a set of types that should be skipped during parsing. Parsing will be attempted for all other types.
93100
* By default, it's an empty set. To skip all types except a specified one, use [convertTo] instead.
94-
* @param useFastDoubleParser whether to use the new _experimental_ FastDoubleParser, defaults to `false` for now.
101+
* @param useFastDoubleParser whether to use [FastDoubleParser], defaults to `true`. Please report any issues you encounter.
95102
*/
96103
public class ParserOptions(
97104
public val locale: Locale? = null,

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.jetbrains.kotlinx.dataframe.api.isColumnGroup
2525
import org.jetbrains.kotlinx.dataframe.api.isFrameColumn
2626
import org.jetbrains.kotlinx.dataframe.api.isSubtypeOf
2727
import org.jetbrains.kotlinx.dataframe.api.map
28+
import org.jetbrains.kotlinx.dataframe.api.parser
2829
import org.jetbrains.kotlinx.dataframe.api.to
2930
import org.jetbrains.kotlinx.dataframe.columns.TypeSuggestion
3031
import org.jetbrains.kotlinx.dataframe.columns.size
@@ -47,6 +48,7 @@ import java.time.format.DateTimeFormatterBuilder
4748
import java.time.temporal.Temporal
4849
import java.time.temporal.TemporalQuery
4950
import java.util.Locale
51+
import kotlin.properties.Delegates
5052
import kotlin.reflect.KClass
5153
import kotlin.reflect.KType
5254
import kotlin.reflect.full.withNullability
@@ -114,6 +116,13 @@ internal class StringParserWithFormat<T>(
114116
}
115117
}
116118

119+
/**
120+
* Central implementation for [GlobalParserOptions].
121+
*
122+
* Can be obtained by a user by calling [DataFrame.parser][DataFrame.Companion.parser].
123+
*
124+
* Defaults are set by [resetToDefault].
125+
*/
117126
internal object Parsers : GlobalParserOptions {
118127

119128
private val formatters: MutableList<DateTimeFormatter> = mutableListOf()
@@ -140,7 +149,7 @@ internal object Parsers : GlobalParserOptions {
140149
skipTypesSet.add(type)
141150
}
142151

143-
override var useFastDoubleParser: Boolean = false
152+
override var useFastDoubleParser by Delegates.notNull<Boolean>()
144153

145154
private var _locale: Locale? = null
146155

@@ -165,7 +174,7 @@ internal object Parsers : GlobalParserOptions {
165174
.toFormatter()
166175
.let { formatters.add(it) }
167176

168-
useFastDoubleParser = false
177+
useFastDoubleParser = true
169178
_locale = null
170179
nullStrings.addAll(listOf("null", "NULL", "NA", "N/A"))
171180
}

0 commit comments

Comments
 (0)