Skip to content

Commit 5bcff90

Browse files
committed
Support more value types in toDataFrame
1 parent 7d98f69 commit 5bcff90

File tree

2 files changed

+26
-1
lines changed
  • src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api
  • tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api

2 files changed

+26
-1
lines changed

src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api/toDataFrame.kt

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,20 @@ import kotlin.reflect.full.memberProperties
3030
import kotlin.reflect.full.withNullability
3131
import kotlin.reflect.jvm.javaField
3232

33-
internal val KClass<*>.isValueType: Boolean get() = this == String::class || this.isSubclassOf(Number::class) || this.isSubclassOf(Temporal::class)
33+
internal val valueTypes = setOf(
34+
String::class,
35+
Boolean::class,
36+
kotlin.time.Duration::class,
37+
kotlinx.datetime.LocalDate::class,
38+
kotlinx.datetime.LocalDateTime::class,
39+
kotlinx.datetime.Instant::class,
40+
)
41+
42+
internal val KClass<*>.isValueType: Boolean get() =
43+
this in valueTypes ||
44+
this.isSubclassOf(Number::class) ||
45+
this.isSubclassOf(Enum::class) ||
46+
this.isSubclassOf(Temporal::class)
3447

3548
internal class CreateDataFrameDslImpl<T>(
3649
override val source: Iterable<T>,

tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,16 @@ class CreateDataFrameTests {
104104
df2.list.kind shouldBe ColumnKind.Frame
105105
df2.a.kind() shouldBe ColumnKind.Group
106106
}
107+
108+
enum class DummyEnum { A }
109+
110+
@Test
111+
fun `don't convert value types`() {
112+
data class Entry(val a: Int, val b: String, val c: Boolean, val e: DummyEnum)
113+
114+
val df = listOf(Entry(1, "s", true, DummyEnum.A)).toDataFrame(depth = 100)
115+
df.columns().forEach {
116+
it.kind shouldBe ColumnKind.Value
117+
}
118+
}
107119
}

0 commit comments

Comments
 (0)