File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
main/kotlin/org/jetbrains/kotlinx/dataframe/api
test/kotlin/org/jetbrains/kotlinx/dataframe/api Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,25 @@ public fun <T> Iterable<DataRow<T>>.toDataFrame(): DataFrame<T> {
6565}
6666
6767@JvmName(" toDataFrameMapStringAnyNullable" )
68- public fun Iterable <Map <String , * >>.toDataFrame (): DataFrame <* > = map { it.toDataRow() }.toDataFrame()
68+ public fun Iterable <Map <String , Any ?>>.toDataFrame (): AnyFrame {
69+ val list = asList()
70+ if (list.isEmpty()) return DataFrame .empty()
71+
72+ val allKeys = linkedSetOf<String >()
73+ for (row in this ) {
74+ allKeys.addAll(row.keys)
75+ }
76+
77+ val columns = allKeys.map { key ->
78+ val values = ArrayList <Any ?>(list.size)
79+ for (row in this ) {
80+ values.add(row[key])
81+ }
82+ DataColumn .createByInference(key, values)
83+ }
84+
85+ return columns.toDataFrame()
86+ }
6987
7088@JvmName(" toDataFrameAnyColumn" )
7189public fun Iterable<AnyBaseCol>.toDataFrame (): AnyFrame = dataFrameOf(this )
Original file line number Diff line number Diff line change @@ -452,6 +452,8 @@ class CreateDataFrameTests {
452452 df[" b" ][0 ] shouldBe true
453453 df[" c" ][1 ] shouldBe 2
454454 df[" d" ][1 ] shouldBe false
455+ df.columns().all { it.type().isMarkedNullable } shouldBe true
456+ df[" a" ].type() shouldBe typeOf<Int ?>()
455457 }
456458
457459 class NoPublicPropsClass (private val a : Int , private val b : String )
You can’t perform that action at this time.
0 commit comments