Skip to content

Commit d161cc1

Browse files
Automated commit of generated code
1 parent b121286 commit d161cc1

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/constructors.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
1313
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
1414
import org.jetbrains.kotlinx.dataframe.annotations.Refine
1515
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
16+
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
1617
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
1718
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
1819
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
@@ -269,6 +270,15 @@ public inline fun <reified T> column(values: Iterable<T>): DataColumn<T> =
269270
allColsMakesColGroup = true,
270271
).forceResolve()
271272

273+
@Refine
274+
@Interpretable("ColumnOfPairs")
275+
public fun columnOf(vararg columns: Pair<String, AnyBaseCol>): ColumnGroup<*> =
276+
dataFrameOf(
277+
columns.map { (name, col) ->
278+
col.rename(name)
279+
},
280+
).asColumnGroup()
281+
272282
// endregion
273283

274284
// region create DataFrame
@@ -290,6 +300,12 @@ public fun dataFrameOf(columns: Iterable<AnyBaseCol>): DataFrame<*> {
290300
return DataFrameImpl<Unit>(cols, nrow)
291301
}
292302

303+
@Refine
304+
@JvmName("dataFrameOfColumns")
305+
@Interpretable("DataFrameOfPairs")
306+
public fun dataFrameOf(vararg columns: Pair<String, AnyBaseCol>): DataFrame<*> =
307+
dataFrameOf(columns.map { (name, col) -> col.rename(name) })
308+
293309
public fun dataFrameOf(vararg header: ColumnReference<*>): DataFrameBuilder = DataFrameBuilder(header.map { it.name() })
294310

295311
public fun dataFrameOf(vararg columns: AnyBaseCol): DataFrame<*> = dataFrameOf(columns.asIterable())

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Create.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,21 @@ class Create : TestBase() {
261261
// SampleEnd
262262
}
263263

264+
@Test
265+
@TransformDataFrameExpressions
266+
fun createNestedDataFrameInplace() {
267+
// SampleStart
268+
// DataFrame with 2 columns and 3 rows
269+
val df = dataFrameOf(
270+
"name" to columnOf(
271+
"firstName" to columnOf("Alice", "Bob", "Charlie"),
272+
"lastName" to columnOf("Cooper", "Dylan", "Daniels"),
273+
),
274+
"age" to columnOf(15, 20, 100),
275+
)
276+
// SampleEnd
277+
}
278+
264279
@Test
265280
@TransformDataFrameExpressions
266281
fun createDataFrameWithFill() {

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,6 +1934,21 @@ class DataFrameTests : BaseTest() {
19341934
df.columns().forEach { col -> col.forEachIndexed { row, value -> value shouldBe row + 1 } }
19351935
}
19361936

1937+
@Test
1938+
fun `create nested dataframe inplace`() {
1939+
val df = dataFrameOf(
1940+
"a" to columnOf("1"),
1941+
"b" to columnOf(
1942+
"c" to columnOf("2"),
1943+
),
1944+
"d" to columnOf(dataFrameOf("a")(123)),
1945+
"gr" to listOf("1").toDataFrame().asColumnGroup(),
1946+
)
1947+
1948+
df.columnNames() shouldBe listOf("a", "b", "d", "gr")
1949+
df.getColumnGroup("gr")["value"].values() shouldBe listOf("1")
1950+
}
1951+
19371952
@Test
19381953
fun `get typed column by name`() {
19391954
val col = df.getColumn("name").cast<String>()

0 commit comments

Comments
 (0)