Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map<String, Any?>.toDataRow() function? #719

Open
Jolanrensen opened this issue Jun 4, 2024 · 1 comment
Open

Map<String, Any?>.toDataRow() function? #719

Jolanrensen opened this issue Jun 4, 2024 · 1 comment
Labels
enhancement New feature or request good first issue Good issues to pick-up for newcomers
Milestone

Comments

@Jolanrensen
Copy link
Collaborator

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 #710 possible (so to construct a DataFrame from rows instead of from columns, albeit at a performance cost).

@Jolanrensen Jolanrensen added the enhancement New feature or request label Jun 4, 2024
@zaleslaw zaleslaw added the good first issue Good issues to pick-up for newcomers label Jul 19, 2024
@zaleslaw zaleslaw added this to the 0.14.0 milestone Jul 19, 2024
@zaleslaw zaleslaw modified the milestones: 0.14.0, 0.15.0, Backlog Sep 16, 2024
@Jolanrensen
Copy link
Collaborator Author

Jolanrensen commented Sep 27, 2024

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good issues to pick-up for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants