holgerbrandl / krangl

krangl is a {K}otlin DSL for data w{rangl}ing
MIT License
560 stars 50 forks source link

dataFrameOf fails with no rows #125

Open ablaagaard opened 3 years ago

ablaagaard commented 3 years ago

I tried dataFrameOf("Col1", "Col2")() but it fails with "Provided data does not coerce to tabular shape"

Maybe there is a better way to create an empty DataFrame with column names

holgerbrandl commented 3 years ago

No you're right. It should allow creating empty data-frames in exactly that way.

holgerbrandl commented 3 years ago

It turned out to be not that easy. The problem is the types of columns. With data, we can do type introspection, but without data we simply do not know the types of columns. So it might be that the short syntax is not applicable and we'd need to do

dataFrameOf(StringCol("user", emptyArray()), DoubleCol("salary", emptyArray()))

What do you think?

ablaagaard commented 3 years ago

I believe I saw some column type conversion somewhere - like when you insert a String in Double column, then the column type is converted? Maybe following a similar pattern the column type doesn't really matter when it is empty, and can be inferred later, if data is added?