Skip to content

Add API to unfold object-columns into properties via reflection #159

@holgerbrandl

Description

@holgerbrandl

As with unfold() in krangl (see https://holgerbrandl.github.io/krangl/data_model/#to-type-or-not-to-type), it would be great if kotlin-df could provide a similar API. Clearly, this could be done manually using df.add(), but with many attributes this is very tedious. And in krangl we've seen that this can be done very efficiently via reflection.

Example (from krangl but yet missing in kdf):

data class City(val name:String, val code:Int)
data class Person(val name:String, val address:City)

val persons : List<Person> = listOf(
    Person("Max", City("Dresden", 12309)),
    Person("Anna", City("Berlin", 10115))
)

val personsDF: DataFrame = persons.asDataFrame() // <- Also sems missing API in kdf?

// unfold City attributes into different columns
personsDF.unfold<City>("address")  // <- Missing API in kdf

For impl see https://github.com/holgerbrandl/krangl/blob/49418b2ca6ee6ae165c034e56e4da77e4707f7ad/src/main/kotlin/krangl/Builder.kt#L115

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions