Skip to content

Updated parse documentation #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ internal object Parsers : GlobalParserOptions {
parser
},

// kotlin.time.duration
// kotlin.time.Duration
stringParser { catchSilent { Duration.parse(it) } },

// java.time.duration
// java.time.Duration
stringParser { catchSilent { java.time.Duration.parse(it) } },

// java.time.LocalTime
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ internal object Parsers : GlobalParserOptions {
parser
},

// kotlin.time.duration
// kotlin.time.Duration
stringParser { catchSilent { Duration.parse(it) } },

// java.time.duration
// java.time.Duration
stringParser { catchSilent { java.time.Duration.parse(it) } },

// java.time.LocalTime
Expand Down
26 changes: 15 additions & 11 deletions docs/StardustDocs/topics/parse.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[//]: # (title: parse)
<!---IMPORT org.jetbrains.kotlinx.dataframe.samples.api.Modify-->

Returns [`DataFrame`](DataFrame.md) in which given `String` columns are parsed into other types.
Returns a [`DataFrame`](DataFrame.md) in which the given `String` columns are parsed into other types.

Special case of [convert](convert.md) operation.
This is a special case of the [convert](convert.md) operation.

<!---FUN parseAll-->

Expand All @@ -14,7 +14,7 @@ df.parse()
<dataFrame src="org.jetbrains.kotlinx.dataframe.samples.api.Modify.parseAll.html"/>
<!---END-->

To parse only particular columns use [column selector](ColumnSelectors.md):
To parse only particular columns use a [column selector](ColumnSelectors.md):

<!---FUN parseSome-->

Expand All @@ -25,19 +25,22 @@ df.parse { age and weight }
<dataFrame src="org.jetbrains.kotlinx.dataframe.samples.api.Modify.parseSome.html"/>
<!---END-->

`parse` tries to parse every`String` column into one of supported types in the following order:
`parse` tries to parse every `String` column into one of supported types in the following order:
* `Int`
* `Long`
* `LocalDateTime`
* `LocalDate`
* `LocalTime`
* `URL`
* `Double`
* `Instant` (`kotlinx.datetime` and `java.time`)
* `LocalDateTime` (`kotlinx.datetime` and `java.time`)
* `LocalDate` (`kotlinx.datetime` and `java.time`)
* `Duration` (`kotlin.time` and `java.time`)
* `LocalTime` (`java.time`)
* `URL` (`java.net`)
* `Double` (with optional locale settings)
* `Boolean`
* `BigDecimal`
* `JSON` (arrays and objects)

Available parser options:
* `locale: Locale` is used to parse numbers
* `locale: Locale` is used to parse doubles
* `dateTimePattern: String` is used to parse date and time
* `dateTimeFormatter: DateTimeFormatter` is used to parse date and time
* `nullStrings: List<String>` is used to treat particular strings as `null` value. Default null strings are **"null"** and **"NULL"**
Expand All @@ -51,7 +54,8 @@ df.parse(options = ParserOptions(locale = Locale.CHINA, dateTimeFormatter = Date
<dataFrame src="org.jetbrains.kotlinx.dataframe.samples.api.Modify.parseWithOptions.html"/>
<!---END-->

You can also set global parser options that will be used by default in [`read`](read.md), [`convert`](convert.md) and `parse` operations:
You can also set global parser options that will be used by default in [`read`](read.md), [`convert`](convert.md),
and `parse` operations:

<!---FUN globalParserOptions-->

Expand Down