Skip to content

Commit 72c8a17

Browse files
committed
copied some kdoc to denote the difference between DataColumn.tryParse and parse.
1 parent 5057eeb commit 72c8a17

File tree

1 file changed

+17
-0
lines changed
  • core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api

1 file changed

+17
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
77
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
88
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
99
import org.jetbrains.kotlinx.dataframe.impl.api.Parsers
10+
import org.jetbrains.kotlinx.dataframe.impl.api.StringParser
1011
import org.jetbrains.kotlinx.dataframe.impl.api.parseImpl
1112
import org.jetbrains.kotlinx.dataframe.impl.api.tryParseImpl
1213
import org.jetbrains.kotlinx.dataframe.typeClass
@@ -55,13 +56,29 @@ public data class ParserOptions(
5556
}
5657
}
5758

59+
/** @include [tryParseImpl] */
5860
public fun DataColumn<String?>.tryParse(options: ParserOptions? = null): DataColumn<*> = tryParseImpl(options)
5961

6062
public fun <T> DataFrame<T>.parse(options: ParserOptions? = null): DataFrame<T> =
6163
parse(options) {
6264
colsAtAnyDepth { !it.isColumnGroup() }
6365
}
6466

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+
*/
6582
public fun DataColumn<String?>.parse(options: ParserOptions? = null): DataColumn<*> =
6683
tryParse(options).also { if (it.typeClass == String::class) error("Can't guess column type") }
6784

0 commit comments

Comments
 (0)