Skip to content

Commit 137a8fd

Browse files
from map to data row + test
1 parent 3b5924f commit 137a8fd

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/typeConversions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public fun <T> DataRow<T>.toDataFrame(): DataFrame<T> = owner[index..index]
406406

407407
public fun AnyRow.toMap(): Map<String, Any?> = df().columns().associate { it.name() to it[index] }
408408

409-
public fun Map<String, Any?>.toDataRow() : DataRow<*> {
409+
public fun Map<String, Any?>.toDataRow(): DataRow<*> {
410410
val df = mapValues { listOf(it.value) }.toDataFrame()
411411
return DataRowImpl(0, df)
412412
}

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataRowTests.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.jetbrains.kotlinx.dataframe.api.relative
2121
import org.jetbrains.kotlinx.dataframe.api.rowMean
2222
import org.jetbrains.kotlinx.dataframe.api.rowStd
2323
import org.jetbrains.kotlinx.dataframe.api.rowSum
24+
import org.jetbrains.kotlinx.dataframe.api.toDataRow
2425
import org.jetbrains.kotlinx.dataframe.api.toDouble
2526
import org.jetbrains.kotlinx.dataframe.api.transposeTo
2627
import org.jetbrains.kotlinx.dataframe.api.update
@@ -118,4 +119,12 @@ class DataRowTests : BaseTest() {
118119
typed[1].relative(-2..2) shouldBe typed[0..3]
119120
typed[1].relative(listOf(2, -1, -3, 0)) shouldBe typed[3, 0, 1]
120121
}
122+
123+
@Test
124+
fun toDataRow() {
125+
val map = mapOf<String, Any?>("a" to 1, "b" to true)
126+
val row = map.toDataRow()
127+
row["a"] shouldBe 1
128+
row["b"] shouldBe true
129+
}
121130
}

0 commit comments

Comments
 (0)