Skip to content

Commit e1668f8

Browse files
committed
Merge branch 'master' into pivot-fix
2 parents df4c997 + c40fb04 commit e1668f8

File tree

319 files changed

+53667
-143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

319 files changed

+53667
-143
lines changed

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ dependencies {
5252
api(project(":dataframe-jdbc"))
5353
}
5454

55-
private enum class Version : Comparable<Version> {
55+
enum class Version : Comparable<Version> {
5656
SNAPSHOT, DEV, ALPHA, BETA, RC, STABLE;
5757
}
5858

59-
private fun String.findVersion(): Version {
59+
fun String.findVersion(): Version {
6060
val version = this.lowercase()
6161
return when {
6262
"snapshot" in version -> Version.SNAPSHOT

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.jetbrains.kotlinx.dataframe
22

33
import org.jetbrains.kotlinx.dataframe.aggregation.Aggregatable
44
import org.jetbrains.kotlinx.dataframe.aggregation.AggregateGroupedBody
5+
import org.jetbrains.kotlinx.dataframe.annotations.HasSchema
56
import org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl
67
import org.jetbrains.kotlinx.dataframe.api.add
78
import org.jetbrains.kotlinx.dataframe.api.cast
@@ -29,6 +30,7 @@ import kotlin.reflect.KType
2930
*
3031
* @param T Schema marker. It identifies column schema and is used to generate schema-specific extension properties for typed data access. It is covariant, so `DataFrame<A>` is assignable to variable of type `DataFrame<B>` if `A` is a subtype of `B`.
3132
*/
33+
@HasSchema(schemaArg = 0)
3234
public interface DataFrame<out T> : Aggregatable<T>, ColumnsContainer<T> {
3335

3436
public companion object {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ public interface DataRow<out T> {
4343
return value as AnyRow
4444
}
4545

46+
public fun getFrameColumn(columnName: String): AnyFrame {
47+
val value = get(columnName)
48+
if (value == null) {
49+
val kind = df()[columnName].kind()
50+
if (kind != ColumnKind.Frame) {
51+
error("Cannot cast null value of a $kind to a ${DataFrame::class}")
52+
}
53+
}
54+
return value as AnyFrame
55+
}
56+
4657
public fun getOrNull(name: String): Any?
4758
public fun <R> getValueOrNull(column: ColumnReference<R>): R?
4859

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/aggregation/AggregateDsl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.jetbrains.kotlinx.dataframe.aggregation
22

33
import org.jetbrains.kotlinx.dataframe.DataFrame
4+
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
45
import org.jetbrains.kotlinx.dataframe.api.ColumnSelectionDsl
56
import org.jetbrains.kotlinx.dataframe.api.pathOf
67
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
@@ -12,6 +13,7 @@ import kotlin.reflect.typeOf
1213

1314
public abstract class AggregateDsl<out T> : DataFrame<T>, ColumnSelectionDsl<T> {
1415

16+
@Interpretable("GroupByInto")
1517
public inline infix fun <reified R> R.into(name: String): NamedValue = internal().yield(pathOf(name), this, typeOf<R>())
1618

1719
public inline infix fun <reified R> R.into(column: ColumnAccessor<R>): NamedValue = internal().yield(pathOf(column.name()), this, typeOf<R>())
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.jetbrains.kotlinx.dataframe.annotations
2+
3+
@Target(AnnotationTarget.CLASS)
4+
public annotation class HasSchema(val schemaArg: Int)
5+
6+
/**
7+
* Compiler plugin will evaluate compile time value of the annotated function.
8+
* Needed because some function calls only serve as a part of overall compile time DataSchema evaluation
9+
* There's no need to update return type of such calls
10+
*/
11+
internal annotation class Interpretable(val interpreter: String)
12+
13+
/**
14+
* Compiler plugin will replace return type of calls to the annotated function
15+
*/
16+
internal annotation class Refine
17+
18+
internal annotation class OptInRefine
19+
20+
@Retention(AnnotationRetention.SOURCE)
21+
@Target(AnnotationTarget.FILE, AnnotationTarget.EXPRESSION)
22+
public annotation class DisableInterpretation
23+
24+
@Retention(AnnotationRetention.SOURCE)
25+
@Target(AnnotationTarget.EXPRESSION)
26+
public annotation class Import
27+
28+
@Target(AnnotationTarget.PROPERTY)
29+
public annotation class Order(val order: Int)
30+
31+
@Target(AnnotationTarget.FUNCTION)
32+
internal annotation class Check
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.jetbrains.kotlinx.dataframe.api
2+
3+
import org.jetbrains.kotlinx.dataframe.DataFrame
4+
5+
public interface DataRowSchema
6+
7+
public inline fun <reified T : DataRowSchema> dataFrameOf(vararg rows: T): DataFrame<T> =
8+
rows.asIterable().toDataFrame()
9+
10+
public inline fun <reified T : DataRowSchema> DataFrame<T>.append(vararg rows: T): DataFrame<T> =
11+
concat(dataFrameOf(*rows))

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import org.jetbrains.kotlinx.dataframe.*
4+
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
5+
import org.jetbrains.kotlinx.dataframe.annotations.Refine
46
import org.jetbrains.kotlinx.dataframe.api.Update.UpdateOperationArg
57
import org.jetbrains.kotlinx.dataframe.columns.ColumnKind
68
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
@@ -918,6 +920,8 @@ public fun <T, C> DataFrame<T>.fillNA(vararg columns: ColumnReference<C>): Updat
918920
* If `false`, rows are dropped if any of the selected cells is `null`.
919921
* @param columns The [Columns Selector][org.jetbrains.kotlinx.dataframe.ColumnsSelector] used to select the columns of this [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame] to drop rows in.
920922
*/
923+
@Refine
924+
@Interpretable("DropNulls0")
921925
public fun <T> DataFrame<T>.dropNulls(whereAllNull: Boolean = false, columns: ColumnsSelector<T, *>): DataFrame<T> {
922926
val cols = this[columns]
923927
return if (whereAllNull) drop { row -> cols.all { col -> col[row] == null } }

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import org.jetbrains.kotlinx.dataframe.DataFrame
1212
import org.jetbrains.kotlinx.dataframe.DataRow
1313
import org.jetbrains.kotlinx.dataframe.RowExpression
1414
import org.jetbrains.kotlinx.dataframe.Selector
15+
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
16+
import org.jetbrains.kotlinx.dataframe.annotations.Refine
1517
import org.jetbrains.kotlinx.dataframe.columns.BaseColumn
1618
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
1719
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
@@ -121,6 +123,8 @@ public typealias AddExpression<T, R> = Selector<AddDataRow<T>, R>
121123
* @return new [DataFrame] with added column
122124
* @throws DuplicateColumnNamesException if [DataFrame] already contains a column with given [name]
123125
*/
126+
@Refine
127+
@Interpretable("Add")
124128
public inline fun <reified R, T> DataFrame<T>.add(
125129
name: String,
126130
infer: Infer = Infer.Nulls,
@@ -178,7 +182,10 @@ public class AddDsl<T>(@PublishedApi internal val df: DataFrame<T>) : ColumnsCon
178182
return df.mapToColumn("", infer, expression)
179183
}
180184

181-
public inline infix fun <reified R> String.from(noinline expression: RowExpression<T, R>): Boolean =
185+
@Interpretable("From")
186+
public inline infix fun <reified R> String.from(
187+
noinline expression: RowExpression<T, R>
188+
): Boolean =
182189
add(this, Infer.Nulls, expression)
183190

184191
// TODO: use path instead of name
@@ -192,6 +199,7 @@ public class AddDsl<T>(@PublishedApi internal val df: DataFrame<T>) : ColumnsCon
192199
public inline infix fun <reified R> ColumnAccessor<R>.from(column: ColumnReference<R>): Boolean = name() from column
193200
public inline infix fun <reified R> KProperty<R>.from(column: ColumnReference<R>): Boolean = name from column
194201

202+
@Interpretable("Into")
195203
public infix fun AnyColumnReference.into(name: String): Boolean = add(rename(name))
196204
public infix fun <R> ColumnReference<R>.into(column: ColumnAccessor<R>): Boolean = into(column.name())
197205
public infix fun <R> ColumnReference<R>.into(column: KProperty<R>): Boolean = into(column.name)
@@ -212,6 +220,8 @@ public class AddDsl<T>(@PublishedApi internal val df: DataFrame<T>) : ColumnsCon
212220
public infix fun AddGroup<T>.into(column: AnyColumnGroupAccessor): Unit = into(column.name())
213221
}
214222

223+
@Refine
224+
@Interpretable("AddWithDsl")
215225
public fun <T> DataFrame<T>.add(body: AddDsl<T>.() -> Unit): DataFrame<T> {
216226
val dsl = AddDsl(this)
217227
body(dsl)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

3+
import org.jetbrains.kotlinx.dataframe.DataFrame
34
import org.jetbrains.kotlinx.dataframe.DataRow
45
import org.jetbrains.kotlinx.dataframe.Selector
56
import org.jetbrains.kotlinx.dataframe.aggregation.AggregateDsl
7+
import org.jetbrains.kotlinx.dataframe.aggregation.AggregateGroupedBody
8+
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
9+
import org.jetbrains.kotlinx.dataframe.annotations.Refine
10+
import org.jetbrains.kotlinx.dataframe.impl.aggregateGroupBy
611

712
// region Pivot
813

914
public fun <T, R> Pivot<T>.aggregate(separate: Boolean = false, body: Selector<AggregateDsl<T>, R>): DataRow<T> = delegate { aggregate(separate, body) }
1015

1116
// endregion
17+
18+
@Refine
19+
@Interpretable("Aggregate")
20+
public fun <T, R> Grouped<T>.aggregate(body: AggregateGroupedBody<T, R>): DataFrame<T> {
21+
return aggregateGroupBy((this as GroupBy<*, *>).toDataFrame(), { groups.cast() }, removeColumns = true, body).cast<T>()
22+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.jetbrains.kotlinx.dataframe.api
22

33
import org.jetbrains.kotlinx.dataframe.DataColumn
44
import org.jetbrains.kotlinx.dataframe.DataFrame
5+
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
56
import org.jetbrains.kotlinx.dataframe.api.AndColumnsSelectionDsl.Grammar
67
import org.jetbrains.kotlinx.dataframe.api.AndColumnsSelectionDsl.Grammar.InfixName
78
import org.jetbrains.kotlinx.dataframe.api.AndColumnsSelectionDsl.Grammar.Name
@@ -210,6 +211,7 @@ public interface AndColumnsSelectionDsl {
210211
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] that contains all the columns from the [ColumnsResolvers][org.jetbrains.kotlinx.dataframe.columns.ColumnsResolver] on the left
211212
* and right side of the [and][org.jetbrains.kotlinx.dataframe.api.AndColumnsSelectionDsl.and] operator.
212213
*/
214+
@Interpretable("And0")
213215
public infix fun <C> ColumnsResolver<C>.and(other: ColumnsResolver<C>): ColumnSet<C> = ColumnsList(this, other)
214216

215217
/** ## And Operator

0 commit comments

Comments
 (0)