Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ import kotlinx.datetime.toLocalDateTime
import org.jetbrains.kotlinx.dataframe.AnyBaseCol
import org.jetbrains.kotlinx.dataframe.AnyCol
import org.jetbrains.kotlinx.dataframe.AnyFrame
import org.jetbrains.kotlinx.dataframe.ColumnsContainer
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.RowColumnExpression
import org.jetbrains.kotlinx.dataframe.RowValueExpression
import org.jetbrains.kotlinx.dataframe.annotations.*
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
import org.jetbrains.kotlinx.dataframe.dataTypes.IFRAME
Expand Down Expand Up @@ -111,6 +114,9 @@ public inline fun <T, C, reified R> Convert<T, C>.with(
noinline rowConverter: RowValueExpression<T, C, R>
): DataFrame<T> = with(Infer.Nulls, rowConverter)

public fun <T, C, R> Convert<T, DataRow<C>>.asFrame(body: ColumnsContainer<T>.(ColumnGroup<C>) -> DataFrame<R>): DataFrame<T> =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it covered by unit test? please add

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

to { body(this, it.asColumnGroup()).asColumnGroup(it.name()) }

public inline fun <T, C, reified R> Convert<T, C>.perRowCol(
infer: Infer = Infer.Nulls,
noinline expression: RowColumnExpression<T, C, R>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ class Modify : TestBase() {
// SampleEnd
}

@Test
@TransformDataFrameExpressions
fun convertAsFrame() {
// SampleStart
df.convert { name }.asFrame { it.add("fullName") { "$firstName $lastName" } }
// SampleEnd
}

@Test
@TransformDataFrameExpressions
fun parseAll() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,4 +661,10 @@ class DataFrameTreeTests : BaseTest() {
val a: DataFrame<NameAndCity> = typed2["nameAndCity"].cast<DataRow<NameAndCity>>().asDataFrame()
val b: DataFrame<NameAndCity> = typed2[nameAndCity].cast<NameAndCity>().asDataFrame()
}

@Test
fun `convert ColumnGroup as Frame`() {
val df = typed2.convert { nameAndCity }.asFrame { it.remove { city } }
df.nameAndCity.columns() shouldBe typed2.nameAndCity.remove { city }.columns()
}
}
Loading