Skip to content

Commit

Permalink
ktlint automatic reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolanrensen committed Jun 27, 2024
1 parent 0bf30ae commit a0b2e44
Show file tree
Hide file tree
Showing 313 changed files with 8,053 additions and 6,613 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,42 +25,61 @@ public interface ColumnsContainer<out T> {
// region columns

public fun columns(): List<AnyCol>

public fun columnsCount(): Int

public fun containsColumn(name: String): Boolean

public fun containsColumn(path: ColumnPath): Boolean

public fun getColumnIndex(name: String): Int

// endregion

// region getColumnOrNull

public fun getColumnOrNull(name: String): AnyCol?

public fun getColumnOrNull(index: Int): AnyCol?

public fun <R> getColumnOrNull(column: ColumnReference<R>): DataColumn<R>?

public fun <R> getColumnOrNull(column: KProperty<R>): DataColumn<R>?

public fun getColumnOrNull(path: ColumnPath): AnyCol?

public fun <R> getColumnOrNull(column: ColumnSelector<T, R>): DataColumn<R>?

// endregion

// region get

public operator fun get(columnName: String): AnyCol = getColumn(columnName)

public operator fun get(columnPath: ColumnPath): AnyCol = getColumn(columnPath)

public operator fun <R> get(column: DataColumn<R>): DataColumn<R> = getColumn(column.name()).cast()

public operator fun <R> get(column: DataColumn<DataRow<R>>): ColumnGroup<R> = getColumn(column)

public operator fun <R> get(column: DataColumn<DataFrame<R>>): FrameColumn<R> = getColumn(column)

public operator fun <R> get(column: ColumnReference<R>): DataColumn<R> = getColumn(column)

public operator fun <R> get(column: ColumnReference<DataRow<R>>): ColumnGroup<R> = getColumn(column)

public operator fun <R> get(column: ColumnReference<DataFrame<R>>): FrameColumn<R> = getColumn(column)

public operator fun <R> get(column: KProperty<R>): DataColumn<R> = get(column.columnName).cast()
public operator fun <R> get(column: KProperty<DataRow<R>>): ColumnGroup<R> = get(column.columnName).asColumnGroup().cast()
public operator fun <R> get(column: KProperty<DataFrame<R>>): FrameColumn<R> = get(column.columnName).asAnyFrameColumn().castFrameColumn()

public operator fun <R> get(column: KProperty<DataRow<R>>): ColumnGroup<R> =
get(column.columnName).asColumnGroup().cast()

public operator fun <R> get(column: KProperty<DataFrame<R>>): FrameColumn<R> =
get(column.columnName).asAnyFrameColumn().castFrameColumn()

public fun <C> get(columns: ColumnsSelector<T, C>): List<DataColumn<C>>

public fun <C> get(column: ColumnSelector<T, C>): DataColumn<C> = get(column as ColumnsSelector<T, C>).single()

// endregion
Expand Down
30 changes: 16 additions & 14 deletions core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataColumn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,20 @@ public interface DataColumn<out T> : BaseColumn<T> {
name: String,
values: List<T>,
infer: Infer = Infer.None,
): ValueColumn<T> = createValueColumn(
name, values,
getValuesType(
): ValueColumn<T> =
createValueColumn(
name,
values,
typeOf<T>(),
infer
getValuesType(
values,
typeOf<T>(),
infer,
),
)
)

public fun <T> createColumnGroup(name: String, df: DataFrame<T>): ColumnGroup<T> = ColumnGroupImpl(name, df)

public fun <T> createFrameColumn(
name: String,
df: DataFrame<T>,
startIndices: Iterable<Int>,
): FrameColumn<T> =
public fun <T> createFrameColumn(name: String, df: DataFrame<T>, startIndices: Iterable<Int>): FrameColumn<T> =
FrameColumnImpl(name, df.splitByIndices(startIndices.asSequence()).toList(), lazy { df.schema() })

public fun <T> createFrameColumn(
Expand All @@ -102,13 +100,17 @@ public interface DataColumn<out T> : BaseColumn<T> {
nullable: Boolean? = null,
): DataColumn<T> = guessColumnType(name, values, nullable = nullable)

public fun <T> create(name: String, values: List<T>, type: KType, infer: Infer = Infer.None): DataColumn<T> {
return when (type.toColumnKind()) {
public fun <T> create(
name: String,
values: List<T>,
type: KType,
infer: Infer = Infer.None,
): DataColumn<T> =
when (type.toColumnKind()) {
ColumnKind.Value -> createValueColumn(name, values, type, infer)
ColumnKind.Group -> createColumnGroup(name, (values as List<AnyRow?>).concat()).asDataColumn().cast()
ColumnKind.Frame -> createFrameColumn(name, values as List<AnyFrame>).asDataColumn().cast()
}
}

public inline fun <reified T> create(name: String, values: List<T>, infer: Infer = Infer.None): DataColumn<T> =
create(name, values, typeOf<T>(), infer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ import kotlin.reflect.KType
* @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`.
*/
@HasSchema(schemaArg = 0)
public interface DataFrame<out T> : Aggregatable<T>, ColumnsContainer<T> {
public interface DataFrame<out T> :
Aggregatable<T>,
ColumnsContainer<T> {

public companion object {
public val Empty: AnyFrame = DataFrameImpl<Unit>(emptyList(), 0)

public fun empty(nrow: Int = 0): AnyFrame = if (nrow == 0) Empty else DataFrameImpl<Unit>(emptyList(), nrow)

/**
Expand Down Expand Up @@ -84,8 +87,11 @@ public interface DataFrame<out T> : Aggregatable<T>, ColumnsContainer<T> {
// region get rows

public operator fun get(index: Int): DataRow<T>

public operator fun get(indices: Iterable<Int>): DataFrame<T> = getRows(indices)

public operator fun get(range: IntRange): DataFrame<T> = getRows(range)

public operator fun get(first: IntRange, vararg ranges: IntRange): DataFrame<T> =
getRows(headPlusArray(first, ranges).asSequence().flatMap { it.asSequence() }.asIterable())

Expand All @@ -97,6 +103,7 @@ public interface DataFrame<out T> : Aggregatable<T>, ColumnsContainer<T> {
// region plus columns

public operator fun plus(col: AnyBaseCol): DataFrame<T> = add(col)

public operator fun plus(cols: Iterable<AnyBaseCol>): DataFrame<T> = (columns() + cols).toDataFrame().cast()

// endregion
Expand All @@ -107,8 +114,7 @@ public interface DataFrame<out T> : Aggregatable<T>, ColumnsContainer<T> {
/**
* Returns a list of columns selected by [columns], a [ColumnsSelectionDsl].
*/
public operator fun <T, C> DataFrame<T>.get(columns: ColumnsSelector<T, C>): List<DataColumn<C>> =
this.get(columns)
public operator fun <T, C> DataFrame<T>.get(columns: ColumnsSelector<T, C>): List<DataColumn<C>> = this.get(columns)

public operator fun <T> DataFrame<T>.get(first: AnyColumnReference, vararg other: AnyColumnReference): DataFrame<T> =
select { (listOf(first) + other).toColumnSet() }
Expand Down
38 changes: 37 additions & 1 deletion core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/DataRow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,24 @@ public interface DataRow<out T> {
// region get cell value

public operator fun get(columnIndex: Int): Any?

public operator fun <R> get(expression: RowExpression<T, R>): R = expression(this, this)

public operator fun <R> get(column: ColumnReference<R>): R

public operator fun <R> get(columns: List<ColumnReference<R>>): List<R> = columns.map { get(it) }

public operator fun <R> get(property: KProperty<R>): R = get(property.columnName) as R
public operator fun get(first: AnyColumnReference, vararg other: AnyColumnReference): DataRow<T> = owner.get(first, *other)[index]

public operator fun get(first: AnyColumnReference, vararg other: AnyColumnReference): DataRow<T> =
owner.get(first, *other)[index]

public operator fun get(first: String, vararg other: String): DataRow<T> = owner.get(first, *other)[index]

public operator fun get(path: ColumnPath): Any? = owner.get(path)[index]

public operator fun get(name: String): Any?

public fun getColumnGroup(columnName: String): AnyRow {
val value = get(columnName)
if (value == null) {
Expand All @@ -55,6 +65,7 @@ public interface DataRow<out T> {
}

public fun getOrNull(name: String): Any?

public fun <R> getValueOrNull(column: ColumnReference<R>): R?

// endregion
Expand All @@ -64,40 +75,65 @@ public interface DataRow<out T> {
public operator fun String.get(vararg path: String): ColumnPath = ColumnPath(listOf(this) + path)

public operator fun <R> ColumnReference<R>.invoke(): R = get(this)

public operator fun <R> String.invoke(): R = this@DataRow[this@invoke] as R

public operator fun <R> ColumnPath.invoke(): R = this@DataRow.get(this) as R

public fun forwardIterable(): Iterable<DataRow<T>> = this.toIterable { it.next }

public fun backwardIterable(): Iterable<DataRow<T>> = this.toIterable { it.prev }

public operator fun <R : Comparable<R>> ColumnReference<R>.compareTo(other: R): Int = get(this).compareTo(other)

public operator fun ColumnReference<Int>.plus(a: Int): Int = get(this) + a

public operator fun ColumnReference<Long>.plus(a: Long): Long = get(this) + a

public operator fun ColumnReference<Double>.plus(a: Double): Double = get(this) + a

public operator fun ColumnReference<String>.plus(a: String): String = get(this) + a

public operator fun Int.plus(col: ColumnReference<Int>): Int = this + get(col)

public operator fun Long.plus(col: ColumnReference<Long>): Long = this + get(col)

public operator fun Double.plus(col: ColumnReference<Double>): Double = this + get(col)

public operator fun ColumnReference<Int>.minus(a: Int): Int = get(this) - a

public operator fun ColumnReference<Long>.minus(a: Long): Long = get(this) - a

public operator fun ColumnReference<Double>.minus(a: Double): Double = get(this) - a

public operator fun Int.minus(col: ColumnReference<Int>): Int = this - get(col)

public operator fun Long.minus(col: ColumnReference<Long>): Long = this - get(col)

public operator fun Double.minus(col: ColumnReference<Double>): Double = this - get(col)

public operator fun ColumnReference<Int>.times(a: Int): Int = get(this) * a

public operator fun ColumnReference<Long>.times(a: Long): Long = get(this) * a

public operator fun ColumnReference<Double>.times(a: Double): Double = get(this) * a

public operator fun ColumnReference<Double>.times(a: Int): Double = get(this) * a

public operator fun ColumnReference<Long>.times(a: Int): Long = get(this) * a

public operator fun ColumnReference<Double>.times(a: Long): Double = get(this) * a

public operator fun ColumnReference<Int>.div(a: Int): Int = get(this) / a

public operator fun ColumnReference<Long>.div(a: Long): Long = get(this) / a

public operator fun ColumnReference<Double>.div(a: Double): Double = get(this) / a

public operator fun ColumnReference<Double>.div(a: Int): Double = get(this) / a

public operator fun ColumnReference<Long>.div(a: Int): Long = get(this) / a

public operator fun ColumnReference<Double>.div(a: Long): Double = get(this) / a

public companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ import org.jetbrains.kotlinx.dataframe.impl.columnName
import kotlin.reflect.KProperty
import kotlin.reflect.typeOf

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

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

public inline infix fun <reified R> R.into(column: ColumnAccessor<R>): NamedValue = internal().yield(pathOf(column.name()), this, typeOf<R>())
public inline infix fun <reified R> R.into(column: ColumnAccessor<R>): NamedValue =
internal().yield(pathOf(column.name()), this, typeOf<R>())

public inline infix fun <reified R> R.into(column: KProperty<R>): NamedValue = internal().yield(pathOf(column.columnName), this, typeOf<R>())
public inline infix fun <reified R> R.into(column: KProperty<R>): NamedValue =
internal().yield(pathOf(column.columnName), this, typeOf<R>())

public infix fun <R> R.default(defaultValue: R): Any = when (this) {
is NamedValue -> this.also { it.default = defaultValue }
else -> ValueWithDefault(this, defaultValue)
}
public infix fun <R> R.default(defaultValue: R): Any =
when (this) {
is NamedValue -> this.also { it.default = defaultValue }
else -> ValueWithDefault(this, defaultValue)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ public data class NamedValue private constructor(
val value: Any?,
val type: KType?,
var default: Any?,
val guessType: Boolean = false
val guessType: Boolean = false,
) {
public companion object {
internal fun create(path: ColumnPath, value: Any?, type: KType?, defaultValue: Any?, guessType: Boolean = false): NamedValue = when (value) {
is ValueWithDefault<*> -> create(path, value.value, type, value.default, guessType)
else -> NamedValue(path, value, type, defaultValue, guessType)
}
internal fun create(
path: ColumnPath,
value: Any?,
type: KType?,
defaultValue: Any?,
guessType: Boolean = false,
): NamedValue =
when (value) {
is ValueWithDefault<*> -> create(path, value.value, type, value.default, guessType)
else -> NamedValue(path, value, type, defaultValue, guessType)
}

internal fun aggregator(builder: AggregateGroupedDsl<*>): NamedValue =
NamedValue(emptyPath(), builder, null, null, false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public annotation class ImportDataSchema(
)

public enum class DataSchemaVisibility {
INTERNAL, IMPLICIT_PUBLIC, EXPLICIT_PUBLIC
INTERNAL,
IMPLICIT_PUBLIC,
EXPLICIT_PUBLIC,
}

public annotation class CsvOptions(
public val delimiter: Char,
)
public annotation class CsvOptions(public val delimiter: Char)

/**
* An annotation class that represents options for JDBC connection.
Expand All @@ -65,14 +65,12 @@ public annotation class JdbcOptions(
public val password: String = "",
public val extractCredFromEnv: Boolean = false,
public val tableName: String = "",
public val sqlQuery: String = ""
public val sqlQuery: String = "",
)

public annotation class JsonOptions(

/** Allows the choice of how to handle type clashes when reading a JSON file. */
public val typeClashTactic: JSON.TypeClashTactic = JSON.TypeClashTactic.ARRAY_AND_VALUE_COLUMNS,

/**
* List of [JsonPath]s where instead of a [ColumnGroup], a [FrameColumn]<[KeyValueProperty]>
* will be created.
Expand Down
Loading

0 comments on commit a0b2e44

Please sign in to comment.