Skip to content

Commit 3211749

Browse files
committed
updating docs for Chars in convert and parse
1 parent 3e531c2 commit 3211749

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

docs/StardustDocs/topics/convert.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ df.convert { name }.asColumn { col ->
5757

5858

5959
`convert` supports automatic type conversions between the following types:
60-
* `String` (uses [`parse`](parse.md) to convert from `String` to other types)
60+
* `String`, `Char` (uses [`parse`](parse.md) to convert from `String` to other types)
6161
* `Boolean`
6262
* `Byte`
6363
* `Short`
@@ -72,6 +72,12 @@ df.convert { name }.asColumn { col ->
7272
* `LocalTime` (kotlinx.datetime and java.time)
7373
* `Instant` (kotlinx.datetime, kotlin.time, and java.time)
7474

75+
Note that converting between `Char` and `Int` is done by ASCII character code.
76+
This means the `Char` `'1'` becomes the `Int` `49`.
77+
78+
If you want to convert `Char` `'1'` to the `Int` `1`, use [parse()](parse.md) instead, or use `String`
79+
as intermediate type.
80+
7581
<!---FUN convertTo-->
7682

7783
```kotlin

docs/StardustDocs/topics/parse.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[//]: # (title: parse)
22
<!---IMPORT org.jetbrains.kotlinx.dataframe.samples.api.Modify-->
33

4-
Returns a [`DataFrame`](DataFrame.md) in which the given `String` columns are parsed into other types.
4+
Returns a [`DataFrame`](DataFrame.md) in which the given `String` and `Char` columns are parsed into other types.
55

6-
This is a special case of the [convert](convert.md) operation.
6+
This is a special case of the [](convert.md) operation.
77

88
This parsing operation is sometimes executed implicitly, for example, when [reading from CSV](read.md) or
9-
[type converting from `String` columns](convert.md).
9+
[type converting from `String`/`Char` columns](convert.md).
1010
You can recognize this by the `locale` or `parserOptions` arguments in these functions.
1111

1212
Related operations: [](updateConvert.md)
@@ -20,7 +20,10 @@ df.parse()
2020
<inline-frame src="resources/org.jetbrains.kotlinx.dataframe.samples.api.Modify.parseAll.html" width="100%"/>
2121
<!---END-->
2222

23-
To parse only particular columns use a [column selector](ColumnSelectors.md):
23+
When no columns are specified, all `String` and `Char` columns are parsed,
24+
even those inside [column groups](DataColumn.md#columngroup) and inside [frame columns](DataColumn.md#framecolumn).
25+
26+
To parse only particular columns, use a [column selector](ColumnSelectors.md):
2427

2528
<!---FUN parseSome-->
2629

@@ -33,7 +36,7 @@ df.parse { age and weight }
3336

3437
### Parsing Order
3538

36-
`parse` tries to parse every `String` column into one of supported types in the following order:
39+
`parse` tries to parse every `String`/`Char` column into one of the supported types in the following order:
3740
* `Int`
3841
* `Long`
3942
* `Instant` (`kotlin.time`) (requires `parseExperimentalInstant = true`, available from Kotlin 2.1+.)
@@ -48,6 +51,12 @@ df.parse { age and weight }
4851
* `Uuid` ([`kotlin.uuid.Uuid`](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.uuid/-uuid/)) (requires `parseExperimentalUuid = true`)
4952
* `BigDecimal`
5053
* `JSON` (arrays and objects) (requires the `org.jetbrains.kotlinx:dataframe-json` dependency)
54+
* `Char`
55+
* `String`
56+
57+
When `.parse()` is called on a single column and the input (`String`/`Char`) type is the same as the output type,
58+
(a.k.a., it cannot be parsed further) an `IllegalStateException` is thrown.
59+
To avoid this, use `col.tryParse()` instead.
5160

5261
### Parser Options
5362

0 commit comments

Comments
 (0)