@@ -7,6 +7,7 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
7
7
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
8
8
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
9
9
import org.jetbrains.kotlinx.dataframe.impl.api.Parsers
10
+ import org.jetbrains.kotlinx.dataframe.impl.api.StringParser
10
11
import org.jetbrains.kotlinx.dataframe.impl.api.parseImpl
11
12
import org.jetbrains.kotlinx.dataframe.impl.api.tryParseImpl
12
13
import org.jetbrains.kotlinx.dataframe.typeClass
@@ -55,13 +56,29 @@ public data class ParserOptions(
55
56
}
56
57
}
57
58
59
+ /* * @include [tryParseImpl] */
58
60
public fun DataColumn<String?>.tryParse (options : ParserOptions ? = null): DataColumn <* > = tryParseImpl(options)
59
61
60
62
public fun <T > DataFrame<T>.parse (options : ParserOptions ? = null): DataFrame <T > =
61
63
parse(options) {
62
64
colsAtAnyDepth { ! it.isColumnGroup() }
63
65
}
64
66
67
+ /* *
68
+ * Tries to parse a column of strings into a column of a different type.
69
+ * Each parser in [Parsers] is run in order until a valid parser is found,
70
+ * a.k.a. that parser was able to parse all values in the column successfully. If a parser
71
+ * fails to parse any value, the next parser is tried.
72
+ *
73
+ * If all fail [IllegalStateException] is thrown. If you don't want this exception to be thrown,
74
+ * use [tryParse] instead.
75
+ *
76
+ * Parsers that are [covered by][StringParser.coveredBy] other parsers are skipped.
77
+ *
78
+ * @param options options for parsing, like providing a locale or a custom date-time formatter
79
+ * @throws IllegalStateException if no valid parser is found
80
+ * @return a new column with parsed values
81
+ */
65
82
public fun DataColumn<String?>.parse (options : ParserOptions ? = null): DataColumn <* > =
66
83
tryParse(options).also { if (it.typeClass == String ::class ) error(" Can't guess column type" ) }
67
84
0 commit comments