Skip to content

Commit

Permalink
Add toDataFrame(KClass) overload to convert type erased lists
Browse files Browse the repository at this point in the history
  • Loading branch information
koperagen committed Aug 19, 2024
1 parent bb55f83 commit 63fb13f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public inline fun <reified T> Iterable<T>.toDataFrame(): DataFrame<T> =
properties()
}

public fun Iterable<*>.toDataFrame(klass: KClass<*>): DataFrame<*> =
createDataFrameImpl(klass) {
properties()
}

@Refine
@Interpretable("toDataFrameDsl")
public inline fun <reified T> Iterable<T>.toDataFrame(noinline body: CreateDataFrameDsl<T>.() -> Unit): DataFrame<T> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,14 @@ class CreateDataFrameTests {
df.participants[0].city
}
}

@Test
fun `convert type erased list to dataframe`() {
val data = listOf(Person("Alice", "Cooper", 15, "London"))
val erased: List<Any?> = data
val df = erased[0]?.let {
erased.toDataFrame(it::class)
}
df shouldBe data.toDataFrame()
}
}

0 comments on commit 63fb13f

Please sign in to comment.