`Map<String, Any?>.toDataRow()` function?
DataFrame has the function pair:
Map<String, Iterable<Any?>>.toDataFrame() and AnyFrame.toMap(): Map<String, List<Any?>>
But for DataRow there's just: AnyRow.toMap(): Map<String, Any?>.
Especially in notebooks it might be helpful to be able to convert a simple Map to a DataRow to get generated accessors.
It might also make notations like https://github.com/Kotlin/dataframe/issues/710 possible (so to construct a DataFrame from rows instead of from columns, albeit at a performance cost).
Additionally, we should allow adding unfolding features like maxDepth to unpack properties. Plus, for large maps, it might be preferable to make a KeyValueDataFrame instead of a DataRow.
Something like this? maybe something more efficient tho
inline fun <reified T> Map<String, T>.toDataRow(
vararg props: KProperty<*>,
maxDepth: Int = 0,
): DataRow<T> =
toDataRow {
properties(roots = props, maxDepth = maxDepth)
}
inline fun <reified T> Map<String, T>.toDataRow(
noinline body: CreateDataFrameDsl<T>.() -> Unit = { properties() },
): DataRow<T> =
values.toDataFrame(body)
.add(keys.toColumn("key"))
.pivot("key").values()
Hey, i would like to work on this issue
Reading the issue, i understand that the returned DataRow should be part of a DataFrame which contains only that row. Is it correct?
@CarloMariaProietti Hi! Thanks for picking this up :)
Yes, that's one way to tackle it, I'll check out the PR to see how it works