Skip to content

Commit ef02605

Browse files
committed
Prepare DataFrame.concat for compiler plugin support
1 parent adbd85c commit ef02605

5 files changed

Lines changed: 24 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ public inline fun <reified T : DataRowSchema> dataFrameOf(vararg rows: T): DataF
88
rows.asIterable().toDataFrame()
99

1010
public inline fun <reified T : DataRowSchema> DataFrame<T>.append(vararg rows: T): DataFrame<T> =
11-
concat(dataFrameOf(*rows))
11+
listOf(this, rows.asIterable().toDataFrame()).concat()

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,24 @@ public fun <T> DataRow<T>.concat(vararg rows: DataRow<T>): DataFrame<T> = (listO
3131

3232
public fun <T> DataFrame<T>.concat(vararg frames: DataFrame<T>): DataFrame<T> = concatImpl(listOf(this) + frames)
3333

34-
public infix fun <T> DataFrame<T>.concat(frame: DataFrame<T>): DataFrame<T> = concatImpl(listOf(this) + frame)
34+
/**
35+
* Vertically concat rows from two DataFrames with different schemas.
36+
* Use [Iterable.concat] to concatenate DataFrames with identical schemas.
37+
*
38+
* #### Schema unification
39+
* If input DataFrame objects have different schemas, every column in the resulting DataFrame will get the lowest common type of the original columns with the same name.
40+
*
41+
* Rows of columns missing in either DataFrame will be filled with `null` values.
42+
*
43+
* Example: `[A: Int, B: String]` concat `[A: Double, C: Float]` yields `[A: Number, B: String?, C: Float?]`.
44+
*
45+
* For more information: {@include [DocumentationUrls.Concat]}
46+
*
47+
*/
48+
@Refine
49+
@Interpretable("DataFrameConcat")
50+
public infix fun <T, T1> DataFrame<T>.concat(frame: DataFrame<T1>): DataFrame<Any> =
51+
concatImpl(listOf(this) + frame).cast()
3552

3653
@JvmName("concatT")
3754
public fun <T> DataFrame<T>.concat(rows: Iterable<DataRow<T>>): DataFrame<T> = (rows() + rows).concat()

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/DocumentationUrls.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,7 @@ internal interface DocumentationUrls {
190190

191191
/** [See "Summary statistics" on the documentation website.]({@include [Url]}/summarystatistics.html) */
192192
typealias Statistics = Nothing
193+
194+
/** [See `concat` on the documentation website.]({@include [Url]}/concat.html) */
195+
typealias Concat = Nothing
193196
}

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/PlaylistJsonTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class PlaylistJsonTest {
194194

195195
@Test
196196
fun union() {
197-
val merged = item.concat(item)
197+
val merged = listOf(item, item).concat()
198198
merged.rowsCount() shouldBe item.rowsCount() * 2
199199
val group = merged.snippet
200200
group.rowsCount() shouldBe item.snippet.rowsCount() * 2

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class DataFrameTreeTests : BaseTest() {
278278

279279
@Test
280280
fun distinct() {
281-
val duplicated = typed2.concat(typed2)
281+
val duplicated = listOf(typed2, typed2).concat()
282282
duplicated.rowsCount() shouldBe typed2.rowsCount() * 2
283283
val dist = duplicated.nameAndCity.distinct()
284284
dist shouldBe typed2.nameAndCity.distinct()

0 commit comments

Comments
 (0)