holgerbrandl
10/19/2024, 6:15 AMdata class Car(val type: String, val model: String)
val cars: DataFrame<*> = dataFrameOf("owner", "car")(
"Max", Car("audi", "a8"),
"Tom", Car("toyota", "corolla")
)
// Unfold the 'car' column into separate columns for each property of the Car class
val unfolded = cars.unfold("car")
I believe the intent is clear from the code, however this fails with (kotilin-datframe v0.14.1) with
> Exception in thread "main" org.jetbrains.kotlinx.dataframe.exceptions.UnequalColumnSizesException: Unequal column sizes. Expected rows count: 2. Actual column sizes:
> owner: 2
> car: 0
> at org.jetbrains.kotlinx.dataframe.impl.DataFrameImpl.init(DataFrameImpl.kt:45)
> at org.jetbrains.kotlinx.dataframe.api.ConstructorsKt.dataFrameOf(constructors.kt:267)
> at org.jetbrains.kotlinx.dataframe.api.ToDataFrameKt.toDataFrameAnyColumn(toDataFrame.kt:65)
I believe the problem is the lack of type information for the column car
, but it's unclear to me how to provide it.roman.belov
10/19/2024, 3:41 PMJolan Rensen [JB]
10/21/2024, 12:15 PMAny
. Then unfold
has no way to guess the properties of the class anymore. You can see this if you print the .schema()
of cars
.
I'll make an issue for it. In the meantime you can sorta "force" the df to recognize the "car" column as `Car`:
val cars: DataFrame<*> = dataFrameOf("owner", "car")(
"Max", Car("audi", "a8"),
"Tom", Car("toyota", "corolla"),
).convert("car").with { it as Car }
then unfold
works fineJolan Rensen [JB]
10/21/2024, 12:20 PMholgerbrandl
10/21/2024, 9:04 PM