Skip to content

Commit 7951e04

Browse files
Automated commit of generated code
1 parent 8142e5b commit 7951e04

File tree

5 files changed

+87
-34
lines changed

5 files changed

+87
-34
lines changed

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

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import kotlinx.datetime.LocalDateTime
55
import kotlinx.datetime.LocalTime
66
import kotlinx.datetime.TimeZone
77
import kotlinx.datetime.toLocalDateTime
8+
import kotlinx.datetime.toStdlibInstant
89
import org.jetbrains.kotlinx.dataframe.AnyBaseCol
910
import org.jetbrains.kotlinx.dataframe.AnyCol
1011
import org.jetbrains.kotlinx.dataframe.AnyFrame
@@ -1281,6 +1282,24 @@ public fun DataColumn<String>.convertToStdlibInstant(): DataColumn<StdlibInstant
12811282
public fun DataColumn<String?>.convertToStdlibInstant(): DataColumn<StdlibInstant?> =
12821283
map { it?.let { StdlibInstant.parse(it) } }
12831284

1285+
/**
1286+
* Converts values in this [kotlinx.datetime.Instant] column to [kotlin.time.Instant].
1287+
*
1288+
* @return A new [DataColumn] with the [kotlin.time.Instant] values.
1289+
*/
1290+
@JvmName("convertToStdlibInstantFromDeprecatedInstant")
1291+
public fun DataColumn<DeprecatedInstant>.convertToStdlibInstant(): DataColumn<StdlibInstant> =
1292+
map { it.toStdlibInstant() }
1293+
1294+
/**
1295+
* Converts values in this [kotlinx.datetime.Instant] column to [kotlin.time.Instant]. Preserves null values.
1296+
*
1297+
* @return A new [DataColumn] with the [kotlin.time.Instant] nullable values.
1298+
*/
1299+
@JvmName("convertToStdlibInstantFromDeprecatedInstantNullable")
1300+
public fun DataColumn<DeprecatedInstant?>.convertToStdlibInstant(): DataColumn<StdlibInstant?> =
1301+
map { it?.toStdlibInstant() }
1302+
12841303
/**
12851304
* __Deprecated__:
12861305
*
@@ -1319,7 +1338,7 @@ public fun <T> Convert<T, String>.toInstant(): DataFrame<T> = asColumn { it.conv
13191338
*
13201339
* ### Examples:
13211340
* ```kotlin
1322-
* df.convert { timestamp }.toInstant()
1341+
* df.convert { timestamp }.toDeprecatedInstant()
13231342
* ```
13241343
*
13251344
* Migrate to [kotlin.time.Instant] and use [convertToStdlibInstant] at your own pace.
@@ -1345,7 +1364,7 @@ public fun <T> Convert<T, String?>.toDeprecatedInstant(): DataFrame<T> = asColum
13451364
*
13461365
* ### Examples:
13471366
* ```kotlin
1348-
* df.convert { timestamp }.toInstant()
1367+
* df.convert { timestamp }.toDeprecatedInstant()
13491368
* ```
13501369
*
13511370
* Migrate to [kotlin.time.Instant] and use [convertToStdlibInstant] at your own pace.
@@ -1364,20 +1383,20 @@ public fun <T> Convert<T, String?>.toDeprecatedInstant(): DataFrame<T> = asColum
13641383
public fun <T> Convert<T, String>.toDeprecatedInstant(): DataFrame<T> = asColumn { it.convertToDeprecatedInstant() }
13651384

13661385
/**
1367-
* Converts values in the [String] columns previously selected with [convert] to the [StdlibInstant],
1386+
* Converts values in the [String] columns previously selected with [convert] to [kotlin.time.Instant],
13681387
* preserving their original names and positions within the [DataFrame].
13691388
* Preserves null values.
13701389
*
13711390
* For more information: [See `convert` on the documentation website.](https://kotlin.github.io/dataframe/convert.html)
13721391
*
13731392
* ### Examples:
13741393
* ```kotlin
1375-
* df.convert { timestamp }.toInstant()
1394+
* df.convert { timestamp }.toStdlibInstant()
13761395
* ```
13771396
*
13781397
* This function will be renamed to `.toInstant()` in 1.1.
13791398
*
1380-
* @return A new [DataFrame] with the values converted to [StdlibInstant].
1399+
* @return A new [DataFrame] with the values converted to [kotlin.time.Instant].
13811400
*/
13821401
@JvmName("toStdlibInstantFromStringNullable")
13831402
@Refine
@@ -1386,26 +1405,64 @@ public fun <T> Convert<T, String>.toDeprecatedInstant(): DataFrame<T> = asColumn
13861405
public fun <T> Convert<T, String?>.toStdlibInstant(): DataFrame<T> = asColumn { it.convertToStdlibInstant() }
13871406

13881407
/**
1389-
* Converts values in the [String] columns previously selected with [convert] to the [StdlibInstant],
1408+
* Converts values in the [String] columns previously selected with [convert] to [kotlin.time.Instant],
13901409
* preserving their original names and positions within the [DataFrame].
13911410
*
13921411
* For more information: [See `convert` on the documentation website.](https://kotlin.github.io/dataframe/convert.html)
13931412
*
13941413
* ### Examples:
13951414
* ```kotlin
1396-
* df.convert { timestamp }.toInstant()
1415+
* df.convert { timestamp }.toStdlibInstant()
13971416
* ```
13981417
*
13991418
* This function will be renamed to `.toInstant()` in 1.1.
14001419
*
1401-
* @return A new [DataFrame] with the values converted to [StdlibInstant].
1420+
* @return A new [DataFrame] with the values converted to [kotlin.time.Instant].
14021421
*/
14031422
@JvmName("toStdlibInstantFromString")
14041423
@Refine
14051424
@Converter(StdlibInstant::class, nullable = false)
14061425
@Interpretable("ToSpecificType")
14071426
public fun <T> Convert<T, String>.toStdlibInstant(): DataFrame<T> = asColumn { it.convertToStdlibInstant() }
14081427

1428+
/**
1429+
* Converts values in the [kotlinx.datetime.Instant] columns previously selected with [convert] to [kotlin.time.Instant],
1430+
* preserving their original names and positions within the [DataFrame].
1431+
* Preserves null values.
1432+
*
1433+
* For more information: [See `convert` on the documentation website.](https://kotlin.github.io/dataframe/convert.html)
1434+
*
1435+
* ### Examples:
1436+
* ```kotlin
1437+
* df.convert { timestamp }.toStdlibInstant()
1438+
* ```
1439+
*
1440+
* @return A new [DataFrame] with the values converted to [kotlin.time.Instant].
1441+
*/
1442+
@JvmName("toStdlibInstantFromDeprecatedInstantNullable")
1443+
@Refine
1444+
@Converter(StdlibInstant::class, nullable = true)
1445+
@Interpretable("ToSpecificType")
1446+
public fun <T> Convert<T, DeprecatedInstant?>.toStdlibInstant(): DataFrame<T> = asColumn { it.convertToStdlibInstant() }
1447+
1448+
/**
1449+
* Converts values in the [kotlinx.datetime.Instant] columns previously selected with [convert] to the [kotlin.time.Instant],
1450+
* preserving their original names and positions within the [DataFrame].
1451+
*
1452+
* For more information: [See `convert` on the documentation website.](https://kotlin.github.io/dataframe/convert.html)
1453+
*
1454+
* ### Examples:
1455+
* ```kotlin
1456+
* df.convert { timestamp }.toStdlibInstant()
1457+
* ```
1458+
*
1459+
* @return A new [DataFrame] with the values converted to [kotlin.time.Instant].
1460+
*/
1461+
@JvmName("toStdlibInstantFromDeprecatedInstant")
1462+
@Refine
1463+
@Converter(StdlibInstant::class, nullable = false)
1464+
@Interpretable("ToSpecificType")
1465+
public fun <T> Convert<T, DeprecatedInstant>.toStdlibInstant(): DataFrame<T> = asColumn { it.convertToStdlibInstant() }
14091466
// endregion
14101467

14111468
// region toLocalDate

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/Rendering.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package org.jetbrains.kotlinx.dataframe.impl
22

3+
import kotlinx.datetime.LocalDateTime
4+
import kotlinx.datetime.LocalTime
35
import org.jetbrains.kotlinx.dataframe.AnyCol
46
import org.jetbrains.kotlinx.dataframe.AnyFrame
57
import org.jetbrains.kotlinx.dataframe.api.asColumnGroup
@@ -13,8 +15,6 @@ import org.jetbrains.kotlinx.dataframe.schema.DataFrameSchema
1315
import org.jetbrains.kotlinx.dataframe.size
1416
import org.jetbrains.kotlinx.dataframe.type
1517
import java.net.URL
16-
import java.time.LocalDateTime
17-
import java.time.LocalTime
1818
import kotlin.reflect.KType
1919
import kotlin.reflect.KVariance
2020
import kotlin.reflect.full.isSubtypeOf
@@ -72,11 +72,14 @@ internal fun renderType(type: KType?): String {
7272
fullName.removePrefix("java.net.")
7373

7474
type.classifier in listOf(LocalDateTime::class, LocalTime::class) ->
75-
fullName.removePrefix("java.time.")
75+
fullName.removePrefix("kotlinx.datetime.")
7676

7777
fullName.startsWith("kotlin.collections.") ->
7878
fullName.removePrefix("kotlin.collections.")
7979

80+
fullName.startsWith("kotlin.time.") ->
81+
fullName.removePrefix("kotlin.time.")
82+
8083
fullName.startsWith("kotlin.") ->
8184
fullName.removePrefix("kotlin.")
8285

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/convert.kt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
399399

400400
StdlibInstant::class -> convert<Int> { StdlibInstant.fromEpochMilliseconds(it.toLong()) }
401401

402-
// #1350
402+
// Related to migration of kotlinx.datetime.Instant -> kotlin.time.Instant, Issue #1350
403403
DeprecatedInstant::class -> convert<Int> { DeprecatedInstant.fromEpochMilliseconds(it.toLong()) }
404404

405405
JavaLocalDateTime::class -> convert<Int> {
@@ -440,7 +440,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
440440

441441
StdlibInstant::class -> convert<Byte> { StdlibInstant.fromEpochMilliseconds(it.toLong()) }
442442

443-
// #1350
443+
// Related to migration of kotlinx.datetime.Instant -> kotlin.time.Instant, Issue #1350
444444
DeprecatedInstant::class -> convert<Byte> { DeprecatedInstant.fromEpochMilliseconds(it.toLong()) }
445445

446446
JavaLocalDateTime::class -> convert<Byte> {
@@ -481,7 +481,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
481481

482482
StdlibInstant::class -> convert<Short> { StdlibInstant.fromEpochMilliseconds(it.toLong()) }
483483

484-
// #1350
484+
// Related to migration of kotlinx.datetime.Instant -> kotlin.time.Instant, Issue #1350
485485
DeprecatedInstant::class -> convert<Short> { DeprecatedInstant.fromEpochMilliseconds(it.toLong()) }
486486

487487
JavaLocalDateTime::class -> convert<Short> {
@@ -534,7 +534,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
534534

535535
StdlibInstant::class -> convert<Long> { StdlibInstant.fromEpochMilliseconds(it) }
536536

537-
// #1350
537+
// Related to migration of kotlinx.datetime.Instant -> kotlin.time.Instant, Issue #1350
538538
DeprecatedInstant::class -> convert<Long> { DeprecatedInstant.fromEpochMilliseconds(it) }
539539

540540
JavaLocalDateTime::class -> convert<Long> {
@@ -569,13 +569,13 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
569569

570570
JavaLocalTime::class -> convert<StdlibInstant> { it.toLocalTime(defaultTimeZone).toJavaLocalTime() }
571571

572-
// #1350
572+
// Related to migration of kotlinx.datetime.Instant -> kotlin.time.Instant, Issue #1350
573573
DeprecatedInstant::class -> convert<StdlibInstant> { it.toDeprecatedInstant() }
574574

575575
else -> null
576576
}
577577

578-
// #1350
578+
// Related to migration of kotlinx.datetime.Instant -> kotlin.time.Instant, Issue #1350
579579
DeprecatedInstant::class -> when (toClass) {
580580
Long::class -> convert<DeprecatedInstant> { it.toStdlibInstant().toEpochMilliseconds() }
581581

@@ -631,7 +631,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
631631
it.toKotlinInstant().toLocalTime(defaultTimeZone).toJavaLocalTime()
632632
}
633633

634-
// #1350
634+
// Related to migration of kotlinx.datetime.Instant -> kotlin.time.Instant, Issue #1350
635635
DeprecatedInstant::class -> convert<JavaInstant> {
636636
it.toKotlinInstant().toDeprecatedInstant()
637637
}
@@ -682,7 +682,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
682682

683683
StdlibInstant::class -> convert<LocalDateTime> { it.toInstant(defaultTimeZone) }
684684

685-
// #1350
685+
// Related to migration of kotlinx.datetime.Instant -> kotlin.time.Instant, Issue #1350
686686
DeprecatedInstant::class -> convert<LocalDateTime> {
687687
it.toInstant(defaultTimeZone).toDeprecatedInstant()
688688
}
@@ -711,7 +711,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
711711
it.toKotlinLocalDateTime().toInstant(defaultTimeZone)
712712
}
713713

714-
// #1350
714+
// Related to migration of kotlinx.datetime.Instant -> kotlin.time.Instant, Issue #1350
715715
DeprecatedInstant::class -> convert<JavaLocalDateTime> {
716716
it.toKotlinLocalDateTime().toInstant(defaultTimeZone).toDeprecatedInstant()
717717
}
@@ -736,7 +736,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
736736

737737
StdlibInstant::class -> convert<LocalDate> { it.atStartOfDayIn(defaultTimeZone) }
738738

739-
// #1350
739+
// Related to migration of kotlinx.datetime.Instant -> kotlin.time.Instant, Issue #1350
740740
DeprecatedInstant::class -> convert<LocalDate> {
741741
it.atStartOfDayIn(defaultTimeZone).toDeprecatedInstant()
742742
}
@@ -761,7 +761,7 @@ internal fun createConverter(from: KType, to: KType, options: ParserOptions? = n
761761
it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone)
762762
}
763763

764-
// #1350
764+
// Related to migration of kotlinx.datetime.Instant -> kotlin.time.Instant, Issue #1350
765765
DeprecatedInstant::class -> convert<JavaLocalDate> {
766766
it.toKotlinLocalDate().atStartOfDayIn(defaultTimeZone).toDeprecatedInstant()
767767
}

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import io.github.oshai.kotlinlogging.KotlinLogging
44
import kotlinx.datetime.LocalDate
55
import kotlinx.datetime.LocalDateTime
66
import kotlinx.datetime.LocalTime
7-
import kotlinx.datetime.format.DateTimeComponents
87
import kotlinx.datetime.toDeprecatedInstant
98
import kotlinx.datetime.toKotlinLocalDate
109
import kotlinx.datetime.toKotlinLocalDateTime
@@ -217,13 +216,7 @@ internal object Parsers : GlobalParserOptions {
217216
}
218217

219218
private fun String.toInstantOrNull(): StdlibInstant? =
220-
// low chance throwing exception, thanks to using parseOrNull instead of parse
221-
catchSilent {
222-
// Default format used by Instant.parse
223-
DateTimeComponents.Formats.ISO_DATE_TIME_OFFSET
224-
.parseOrNull(this)
225-
?.toInstantUsingOffset()
226-
}
219+
StdlibInstant.parseOrNull(this)
227220
// fallback on the java instant to catch things like "2022-01-23T04:29:60", a.k.a. leap seconds
228221
?: toJavaInstantOrNull()?.toKotlinInstant()
229222

@@ -310,7 +303,7 @@ internal object Parsers : GlobalParserOptions {
310303
}
311304

312305
private fun String.toDurationOrNull(): Duration? =
313-
if (Duration.canParse(this)) {
306+
if (Duration.canParse(this)) { // TODO, migrate to `Duration.parseOrNull()` in Kotlin 2.3.0+
314307
catchSilent { Duration.parse(this) } // will likely succeed
315308
} else {
316309
null

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/parse.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ParseTests {
8686
parsed.type() shouldBe typeOf<LocalDateTime>()
8787
with(parsed[0]) {
8888
month shouldBe Month.JUNE
89-
dayOfMonth shouldBe 3
89+
day shouldBe 3
9090
year shouldBe 2008
9191
hour shouldBe 13
9292
minute shouldBe 5
@@ -95,8 +95,8 @@ class ParseTests {
9595

9696
dateTime.convertToLocalDateTime(pattern, locale) shouldBe parsed
9797
with(dateTime.toDataFrame()) {
98-
convert { dateTime }.toLocalDateTime(pattern)[dateTime] shouldBe parsed
99-
parse(ParserOptions(dateTimePattern = pattern))[dateTime] shouldBe parsed
98+
convert { dateTime }.toLocalDateTime(pattern)[dateTime.name] shouldBe parsed
99+
parse(ParserOptions(dateTimePattern = pattern))[dateTime.name] shouldBe parsed
100100
}
101101

102102
DataFrame.parser.addDateTimePattern(pattern)

0 commit comments

Comments
 (0)