Hi there, can you help me with the following examp...
# datascience
h
Hi there, can you help me with the following example:
Copy code
data 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.
👍 1
r
Oh, looks like some weird bug for me I don't understand why, ATM, but it depends on the placement of the data class. And the code below perfectly works for me, while yours fails: cc @Nikita Klimenko [JB]
j
@holgerbrandl actually, this is a bug, something with detecting visibility in our type guessing system. If you write a class inside a function body, they are not considered "public" and will be cast to
Any
. 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`:
Copy code
val cars: DataFrame<*> = dataFrameOf("owner", "car")(
    "Max", Car("audi", "a8"),
    "Tom", Car("toyota", "corolla"),
).convert("car").with { it as Car }
then
unfold
works fine
https://github.com/Kotlin/dataframe/issues/928 thanks for letting us know 🙂
h
Thanks for your kind support.