Skip to content
Draft
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
3 changes: 0 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ allprojects {
}
tasks.withType<KotlinCompile> {
compilerOptions {
// enables support for kotlin.time.Instant as kotlinx.datetime.Instant was deprecated; Issue #1350
// Can be removed once kotlin.time.Instant is marked "stable".
optIn.add("kotlin.time.ExperimentalTime")
// can be removed once kotlin.uuid.ExperimentalUuidApi is marked "stable".
optIn.add("kotlin.uuid.ExperimentalUuidApi")
}
Expand Down
17 changes: 11 additions & 6 deletions core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/parse.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ public interface GlobalParserOptions {
public var parseExperimentalUuid: Boolean

/**
* Whether to allow parsing to the experimental [kotlin.time.Instant] type.
* By default, this is false and instants are recognized as the deprecated [kotlinx.datetime.Instant] type (#1350).
* Whether to allow parsing to the [kotlin.time.Instant] type.
* This is marked "stable" from Kotlin 2.3.0+, so, by default this is `true`.
*
* NOTE: Interacting with an [Instant][kotlin.time.Instant] in your code might require
* If false, instants are recognized as the deprecated [kotlinx.datetime.Instant] type (#1350).
*
* NOTE: If you are using an older Kotlin version,
* interacting with an [Instant][kotlin.time.Instant] in your code might require
* `@`[OptIn][OptIn]`(`[ExperimentalTime][kotlin.time.ExperimentalTime]`::class)`.
* In notebooks, add `-opt-in=kotlin.time.ExperimentalTime` to the compiler arguments.
*/
Expand Down Expand Up @@ -127,9 +130,11 @@ public interface GlobalParserOptions {
* NOTE: Interacting with a [Uuid][Uuid] in your code might require
* `@`[OptIn][OptIn]`(`[ExperimentalUuidApi][ExperimentalUuidApi]`::class)`.
* In notebooks, add `-opt-in=kotlin.uuid.ExperimentalUuidApi` to the compiler arguments.
* @param parseExperimentalInstant whether to allow parsing to the experimental [kotlin.time.Instant] type.
* By default, this is false and instants are recognized as the deprecated [kotlinx.datetime.Instant] type (#1350).
* NOTE: Interacting with an [Instant][kotlin.time.Instant] in your code might require
* @param parseExperimentalInstant whether to allow parsing to the [kotlin.time.Instant] type.
* This is marked "stable" from Kotlin 2.3.0+, so, by default this is `true`.
* If false, instants are recognized as the deprecated [kotlinx.datetime.Instant] type (#1350).
* NOTE: If you are using an older Kotlin version,
* interacting with an [Instant][kotlin.time.Instant] in your code might require
* `@`[OptIn][OptIn]`(`[ExperimentalTime][kotlin.time.ExperimentalTime]`::class)`.
* In notebooks, add `-opt-in=kotlin.time.ExperimentalTime` to the compiler arguments.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ internal object Parsers : GlobalParserOptions {

useFastDoubleParser = true
parseExperimentalUuid = false
parseExperimentalInstant = false
parseExperimentalInstant = true
_locale = null
nullStrings.addAll(listOf("null", "NULL", "NA", "N/A"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ class GatherTests {

@Test
fun `gather mix of columns`() {
val a by columnOf(1, 1.1)
val b by columnOf(2, 2.2)
val a by columnOf<Number>(1, 1.1)
val b by columnOf<Number>(2, 2.2)

val df = dataFrameOf(a, b)[0..0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GetTests {
val throwable = shouldThrow<IllegalArgumentException> { df[column<Int>("c")] }
throwable.message shouldContain "Column not found: '[c]'"

val added = df.add(A::c) { "3" }[0]
val added = df.add<Any, _>(A::c) { "3" }[0]

shouldThrow<ClassCastException> { added.getValue(c) + 1 }
shouldThrow<ClassCastException> { added.getValue<Int>("c") + 1 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class InferTypeTests {

@Test
fun `infer type 1`() {
val col by columnOf("Alice", 1, 3.5)
val col by columnOf<Comparable<*>>("Alice", 1, 3.5)
col.type() shouldBe typeOf<Comparable<*>>()
val filtered = col.filter { it is String }
filtered.type() shouldBe typeOf<Comparable<*>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ class ParserTests {

@Test(expected = TypeConversionException::class)
fun `converter for mixed column should throw`() {
val col by columnOf(1, "a")
val col by columnOf<Any>(1, "a")
col.convertTo<Int>()
}

@Test
fun `convert mixed column`() {
val col by columnOf(1.0, "1")
val col by columnOf<Any>(1.0, "1")
val converted = col.convertTo<Int>()
converted.type() shouldBe typeOf<Int>()
converted[0] shouldBe 1
Expand All @@ -90,7 +90,7 @@ class ParserTests {

@Test
fun `convert to Boolean`() {
val col by columnOf(BigDecimal(1.0), BigDecimal(0.0), 0, 1, 10L, 0.0, 0.1)
val col by columnOf<Number>(BigDecimal(1.0), BigDecimal(0.0), 0, 1, 10L, 0.0, 0.1)
col.convertTo<Boolean>().shouldBe(
DataColumn.createValueColumn("col", listOf(true, false, false, true, true, false, true), typeOf<Boolean>()),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ class CleaningDataTests {
)

df.convert { recentDelays }.with { it.map { d -> d.toDouble() } }
.split { recentDelays }.default(Double.NaN).into { "delay_$it" }[delay1, delay2, delay3] shouldBe expected
.split { recentDelays }.default<_, _, Number>(Double.NaN)
.into { "delay_$it" }[delay1, delay2, delay3] shouldBe expected

df.convert { "RecentDelays"<List<Int>>() }.with { it.map { d -> d.toDouble() } }
.split { "RecentDelays"<List<Double>>() }.default(Double.NaN).into {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class PrecisionTests {
fun precision() {
columnOf(1.2, 3.2).scale() shouldBe 1
columnOf(1.1232, 3.2).scale() shouldBe 4
columnOf(1.1220001, 12313).scale() shouldBe DEFAULT_PRECISION
columnOf<Number>(1.1220001, 12313).scale() shouldBe DEFAULT_PRECISION
columnOf(1, 2).scale() shouldBe 0
columnOf(1.0, 2).scale() shouldBe 1
columnOf<Number>(1.0, 2).scale() shouldBe 1
columnOf(123121.0, -1231.0).scale() shouldBe 1
columnOf(123121.00001, -1231.120).scale() shouldBe 5
columnOf(0.000343434343434343434343).scale() shouldBe DEFAULT_PRECISION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2351,7 +2351,7 @@ class DataFrameTests : BaseTest() {

@Test
fun splitIntoThisAndNewColumn() {
val split = typed.split { name }.by { listOf(it.dropLast(1), it.last()) }.into("name", "lastChar")
val split = typed.split { name }.by { listOf<Any>(it.dropLast(1), it.last()) }.into("name", "lastChar")
split.columnNames().sorted() shouldBe (typed.columnNames() + "lastChar").sorted()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class DoubleTests {

@Test
fun `filter not null with nans`() {
val age by columnOf(2.3, Double.NaN, 1.0, "asd", 3, 'a')
val age by columnOf<Any>(2.3, Double.NaN, 1.0, "asd", 3, 'a')
val df = dataFrameOf(age)
df.filter { age() == Double.NaN }.nrow shouldBe 1
df.filter { (age() as? Double)?.isNaN() == true }.nrow shouldBe 1
df.filter { age().isNaN }.nrow shouldBe 1
df.filter { it[age].isNaN }.nrow shouldBe 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ class DelimCsvTsvTests {
// use DFs parsers by default for datetime-like columns
val df1 = DataFrame.readCsvStr(csvContent)
df1["with_timezone_offset"].let {
it.type() shouldBe typeOf<DeprecatedInstant>()
it[0] shouldBe DeprecatedInstant.parse("2024-12-12T13:00:00+01:00")
it.type() shouldBe typeOf<StdlibInstant>()
it[0] shouldBe StdlibInstant.parse("2024-12-12T13:00:00+01:00")
}
df1["without_timezone_offset"].let {
it.type() shouldBe typeOf<LocalDateTime>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ abstract class DataFrameJupyterTest :
ReplProvider.forLibrariesTesting(
libraries = setOf("dataframe", "kandy-geo", "kandy"),
extraCompilerArguments = listOf(
"-Xopt-in=kotlin.time.ExperimentalTime",
"-Xopt-in=kotlin.uuid.ExperimentalUuidApi",
),
),
Expand Down
8 changes: 4 additions & 4 deletions docs/StardustDocs/topics/parse.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ df.parse { age and weight }
`parse` tries to parse every `String`/`Char` column into one of the supported types in the following order:
* `Int`
* `Long`
* `Instant` (`kotlin.time`) (requires `parseExperimentalInstant = true`, available from Kotlin 2.1+.)
* `Instant` (`kotlinx.datetime` and `java.time`)
* `Instant` (`kotlin.time`) (requires `parseExperimentalInstant = true`, enabled by default in DataFrame 1.0.0-Beta5)
* `Instant` (`kotlinx.datetime` and `java.time`) (requires `parseExperimentalInstant = false`)
* `LocalDateTime` (`kotlinx.datetime` and `java.time`)
* `LocalDate` (`kotlinx.datetime` and `java.time`)
* `Duration` (`kotlin.time` and `java.time`)
Expand Down Expand Up @@ -84,9 +84,9 @@ Available parser options:
* Enabled by global default
* `parseExperimentalUuid: Boolean` is used to enable or disable parsing to the experimental [`kotlin.uuid.Uuid` class](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.uuid/-uuid/).
* Disabled by global default
* `parseExperimentalInstant: Boolean` is used to enable or disable parsing to the experimental
* `parseExperimentalInstant: Boolean` is used to enable or disable parsing to the
[`kotlin.time.Instant` class](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.time/-instant/), available from Kotlin 2.1+. Will parse to `kotlinx.datetime.Instant` if `false`.
* Disabled by global default
* Disabled by global default, enabled in DataFrame 1.0.0-Beta5.

<!---FUN parseWithOptions-->

Expand Down
2 changes: 1 addition & 1 deletion docs/StardustDocs/v.list
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<!DOCTYPE vars SYSTEM "https://resources.jetbrains.com/writerside/1.0/vars.dtd">
<vars>
<var name="dataFrameVersion" value="1.0.0-Beta4" type="string"/>
<var name="compilerPluginKotlinVersion" value="2.3.0-RC3" type="string"/>
<var name="compilerPluginKotlinVersion" value="2.3.0" type="string"/>
</vars>
Loading
Loading