Skip to content

Commit

Permalink
fixup! ktlint: manual fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolanrensen committed Jun 28, 2024
1 parent f6ee8d5 commit 0a4636a
Show file tree
Hide file tree
Showing 118 changed files with 1,308 additions and 1,921 deletions.
26 changes: 9 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,13 @@ fun String.findVersion(): Version {
// these names of outdated dependencies will not show up in the table output
val dependencyUpdateExclusions = listOf(
// TODO Requires more work to be updated to 1.7.0+, https://github.com/Kotlin/dataframe/issues/594
libs.plugins.kover
.get()
.pluginId,
libs.plugins.kover.get().pluginId,
// TODO 5.8.0 is not possible due to https://github.com/Kotlin/dataframe/issues/595
libs.kotestAssertions.get().name,
// Can't be updated to 7.4.0+ due to Java 8 compatibility
libs.android.gradle.api
.get()
.group,
libs.android.gradle.api.get().group,
// TODO 0.1.6 broke kotlinter, https://github.com/Kotlin/dataframe/issues/598
libs.plugins.korro
.get()
.pluginId,
libs.plugins.korro.get().pluginId,
// Directly dependent on the Gradle version
"org.gradle.kotlin.kotlin-dsl",
)
Expand All @@ -110,16 +104,14 @@ tasks.named<DependencyUpdatesTask>("dependencyUpdates").configure {
doLast {
val outputFile = layout.buildDirectory
.file("../$outputDir/$reportfileName.json")
.get()
.asFile
.get().asFile
when (val outDatedDependencies = DataFrame.readJson(outputFile)["outdated"]["dependencies"][0]) {
is AnyFrame -> {
val df = outDatedDependencies
.select {
cols("group", "name", "version") and {
"available"["milestone"] named "newVersion"
}
}.filter { "name"() !in dependencyUpdateExclusions && "group"() !in dependencyUpdateExclusions }
val df = outDatedDependencies.select {
cols("group", "name", "version") and {
"available"["milestone"] named "newVersion"
}
}.filter { "name"() !in dependencyUpdateExclusions && "group"() !in dependencyUpdateExclusions }
logger.warn("Outdated dependencies found:")
df.print(
rowsLimit = Int.MAX_VALUE,
Expand Down
6 changes: 1 addition & 5 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,7 @@ val changeJarTask by tasks.creating {
doFirst {
tasks.withType<Jar> {
doFirst {
require(
generatedSources.kotlin.srcDirs
.toList()
.isNotEmpty(),
) {
require(generatedSources.kotlin.srcDirs.toList().isNotEmpty()) {
logger.error("`processKDocsMain`'s outputs are empty, did `processKDocsMain` run before this task?")
}
kotlin.sourceSets.main {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,8 @@ internal interface DiffOrNullDocs
@OptIn(ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
public fun <T> DataRow<T>.diff(firstRowResult: Double, expression: RowExpression<T, Double>): Double =
prev()?.let { p ->
expression(
this,
this,
) - expression(p, p)
} ?: firstRowResult
prev()?.let { p -> expression(this, this) - expression(p, p) }
?: firstRowResult

/**
* @include [DiffDocs]
Expand All @@ -116,37 +112,30 @@ public fun <T> DataRow<T>.diff(firstRowResult: Double, expression: RowExpression
@OverloadResolutionByLambdaReturnType
// required to resolve `diff(0) { intValue }`
public fun <T> DataRow<T>.diff(firstRowResult: Int, expression: RowExpression<T, Int>): Int =
prev()?.let { p ->
expression(
this,
this,
) - expression(p, p)
} ?: firstRowResult
prev()?.let { p -> expression(this, this) - expression(p, p) }
?: firstRowResult

/**
* @include [DiffDocs]
*/
public fun <T> DataRow<T>.diff(firstRowResult: Long, expression: RowExpression<T, Long>): Long =
prev()?.let { p -> expression(this, this) - expression(p, p) } ?: firstRowResult
prev()?.let { p -> expression(this, this) - expression(p, p) }
?: firstRowResult

/**
* @include [DiffDocs]
*/
public fun <T> DataRow<T>.diff(firstRowResult: Float, expression: RowExpression<T, Float>): Float =
prev()?.let { p -> expression(this, this) - expression(p, p) } ?: firstRowResult
prev()?.let { p -> expression(this, this) - expression(p, p) }
?: firstRowResult

/**
* @include [DiffOrNullDocs]
*/
@OptIn(ExperimentalTypeInference::class)
@OverloadResolutionByLambdaReturnType
public fun <T> DataRow<T>.diffOrNull(expression: RowExpression<T, Double>): Double? =
prev()?.let { p ->
expression(
this,
this,
) - expression(p, p)
}
prev()?.let { p -> expression(this, this) - expression(p, p) }

/**
* @include [DiffOrNullDocs]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ public value class JsonPath(
JsonPath(
path.toCharArray().let { chars ->
val lastStarIndex = chars.lastIndexOf('*')
chars
.flatMapIndexed { i, c ->
if (i == lastStarIndex) {
index.toString().toCharArray().toList()
} else {
listOf(c)
}
}.joinToString("")
chars.flatMapIndexed { i, c ->
if (i == lastStarIndex) {
index.toString().toCharArray().toList()
} else {
listOf(c)
}
}.joinToString("")
},
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@ public fun <T, R> Pivot<T>.aggregate(separate: Boolean = false, body: Selector<A
@Refine
@Interpretable("Aggregate")
public fun <T, R> Grouped<T>.aggregate(body: AggregateGroupedBody<T, R>): DataFrame<T> =
aggregateGroupBy((this as GroupBy<*, *>).toDataFrame(), {
groups.cast()
}, removeColumns = true, body).cast<T>()
aggregateGroupBy((this as GroupBy<*, *>).toDataFrame(), { groups.cast() }, removeColumns = true, body).cast<T>()
Original file line number Diff line number Diff line change
Expand Up @@ -1159,17 +1159,16 @@ internal fun SingleColumn<DataRow<*>>.allColsExceptInternal(other: ColumnsResolv
internal fun <C> SingleColumn<DataRow<C>>.exceptExperimentalInternal(
other: ColumnsResolver<*>,
): SingleColumn<DataRow<C>> =
ensureIsColumnGroup()
.transformSingle { singleCol ->
val columnsToExcept = singleCol
.asColumnGroup()
.getColumnsWithPaths { other }
.map { it.changePath(singleCol.path + it.path) }
ensureIsColumnGroup().transformSingle { singleCol ->
val columnsToExcept = singleCol
.asColumnGroup()
.getColumnsWithPaths { other }
.map { it.changePath(singleCol.path + it.path) }

val newCols = listOf(singleCol).allColumnsExceptKeepingStructure(columnsToExcept)
val newCols = listOf(singleCol).allColumnsExceptKeepingStructure(columnsToExcept)

newCols as List<ColumnWithPath<DataRow<*>>>
}.singleInternal() as SingleColumn<DataRow<C>>
newCols as List<ColumnWithPath<DataRow<*>>>
}.singleInternal() as SingleColumn<DataRow<C>>

/**
* Functions annotated with this annotation are experimental and will be removed or renamed in the future.
Expand Down
18 changes: 7 additions & 11 deletions core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/append.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,19 @@ public fun <T> DataFrame<T>.append(vararg values: Any?): DataFrame<T> {
"Invalid number of arguments. Multiple of $ncol is expected, but actual was: ${values.size}"
}
val newRows = values.size / ncol
return columns()
.mapIndexed { colIndex, col ->
val newValues = (0 until newRows).map { values[colIndex + it * ncol] }
col.updateWith(col.values + newValues)
}.toDataFrame()
.cast()
return columns().mapIndexed { colIndex, col ->
val newValues = (0 until newRows).map { values[colIndex + it * ncol] }
col.updateWith(col.values + newValues)
}.toDataFrame().cast()
}

public fun <T> DataFrame<T>.appendNulls(numberOfRows: Int = 1): DataFrame<T> {
require(numberOfRows >= 0)
if (numberOfRows == 0) return this
if (ncol == 0) return DataFrame.empty(nrow + numberOfRows).cast()
return columns()
.map { col ->
col.updateWith(col.values + arrayOfNulls(numberOfRows))
}.toDataFrame()
.cast()
return columns().map { col ->
col.updateWith(col.values + arrayOfNulls(numberOfRows))
}.toDataFrame().cast()
}

// endregion
39 changes: 16 additions & 23 deletions core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/col.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,11 @@ public interface ColColumnsSelectionDsl<out _UNUSED> {
* @include [ColReferenceDocs] {@set [CommonColDocs.ReceiverArg] myColumnGroup.}
*/
public fun <C> SingleColumn<DataRow<*>>.col(col: ColumnAccessor<C>): SingleColumn<C> =
this
.ensureIsColumnGroup()
.transformSingle {
val child = it.getCol(col)
?: throw IllegalStateException("Column '${col.path()}' not found in column group '${it.path}'")
listOf(child)
}.singleImpl()
this.ensureIsColumnGroup().transformSingle {
val child = it.getCol(col)
?: throw IllegalStateException("Column '${col.path()}' not found in column group '${it.path}'")
listOf(child)
}.singleImpl()

/**
* @include [ColReferenceDocs] {@set [CommonColDocs.ReceiverArg] myColumnGroup.}
Expand Down Expand Up @@ -238,13 +236,11 @@ public interface ColColumnsSelectionDsl<out _UNUSED> {
* @include [CommonColDocs.ColumnTypeParam]
*/
public fun <C> SingleColumn<DataRow<*>>.col(name: String): SingleColumn<C> =
this
.ensureIsColumnGroup()
.transformSingle {
val child = it.getCol(name)?.cast<C>()
?: throw IllegalStateException("Column '$name' not found in column group '${it.path}'")
listOf(child)
}.singleImpl()
this.ensureIsColumnGroup().transformSingle {
val child = it.getCol(name)?.cast<C>()
?: throw IllegalStateException("Column '$name' not found in column group '${it.path}'")
listOf(child)
}.singleImpl()

/**
* @include [ColNameDocs] {@set [CommonColDocs.ReceiverArg] myColumnGroup.}
Expand Down Expand Up @@ -340,13 +336,11 @@ public interface ColColumnsSelectionDsl<out _UNUSED> {
* @include [CommonColDocs.ColumnTypeParam]
*/
public fun <C> SingleColumn<DataRow<*>>.col(path: ColumnPath): SingleColumn<C> =
this
.ensureIsColumnGroup()
.transformSingle {
val child = it.getCol(path)?.cast<C>()
?: throw IllegalStateException("Column '$path' not found in column group '${it.path}'")
listOf(child)
}.singleImpl()
this.ensureIsColumnGroup().transformSingle {
val child = it.getCol(path)?.cast<C>()
?: throw IllegalStateException("Column '$path' not found in column group '${it.path}'")
listOf(child)
}.singleImpl()

/**
* @include [ColPathDocs] {@set [CommonColDocs.ReceiverArg] myColumnGroup.}
Expand Down Expand Up @@ -512,8 +506,7 @@ public interface ColColumnsSelectionDsl<out _UNUSED> {
* @include [CommonColDocs.ColumnTypeParam]
*/
public fun <C> SingleColumn<DataRow<*>>.col(index: Int): SingleColumn<C> =
this
.ensureIsColumnGroup()
this.ensureIsColumnGroup()
.allColumnsInternal()
.getAt(index)
.cast()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,14 @@ public interface ColGroupColumnsSelectionDsl<out _UNUSED> {
* @include [ColGroupReferenceDocs] {@set [CommonColGroupDocs.ReceiverArg] myColumnGroup.}
*/
public fun <C> SingleColumn<DataRow<*>>.colGroup(colGroup: ColumnAccessor<DataRow<C>>): SingleColumn<DataRow<C>> =
this
.ensureIsColumnGroup()
.transformSingle {
val child = it.getCol(colGroup)
?: throw IllegalStateException(
"ColumnGroup '${colGroup.path()}' not found in column group '${it.path}'",
)
child.data.ensureIsColumnGroup()
listOf(child)
}.singleImpl()
this.ensureIsColumnGroup().transformSingle {
val child = it.getCol(colGroup)
?: throw IllegalStateException(
"ColumnGroup '${colGroup.path()}' not found in column group '${it.path}'",
)
child.data.ensureIsColumnGroup()
listOf(child)
}.singleImpl()

/**
* @include [ColGroupReferenceDocs] {@set [CommonColGroupDocs.ReceiverArg] myColumnGroup.}
Expand Down Expand Up @@ -242,14 +240,12 @@ public interface ColGroupColumnsSelectionDsl<out _UNUSED> {
* @include [CommonColGroupDocs.ColumnGroupTypeParam]
*/
public fun <C> SingleColumn<DataRow<*>>.colGroup(name: String): SingleColumn<DataRow<C>> =
this
.ensureIsColumnGroup()
.transformSingle {
val child = it.getCol(name)?.cast<DataRow<C>>()
?: throw IllegalStateException("Column group '$name' not found in column group '${it.path}'")
child.data.ensureIsColumnGroup()
listOf(child)
}.singleImpl()
this.ensureIsColumnGroup().transformSingle {
val child = it.getCol(name)?.cast<DataRow<C>>()
?: throw IllegalStateException("Column group '$name' not found in column group '${it.path}'")
child.data.ensureIsColumnGroup()
listOf(child)
}.singleImpl()

/**
* @include [ColGroupNameDocs] {@set [CommonColGroupDocs.ReceiverArg] myColumnGroup.}
Expand Down Expand Up @@ -344,8 +340,7 @@ public interface ColGroupColumnsSelectionDsl<out _UNUSED> {
* @include [CommonColGroupDocs.ColumnGroupTypeParam]
*/
public fun <C> SingleColumn<DataRow<*>>.colGroup(path: ColumnPath): SingleColumn<DataRow<C>> =
this
.ensureIsColumnGroup()
this.ensureIsColumnGroup()
.transformSingle {
val child = it.getCol(path)?.cast<DataRow<C>>()
?: throw IllegalStateException("Column group '$path' not found in column group '${it.path}'")
Expand Down Expand Up @@ -563,8 +558,7 @@ public interface ColGroupColumnsSelectionDsl<out _UNUSED> {
* @include [CommonColGroupDocs.ColumnGroupTypeParam]
*/
public fun <C> SingleColumn<DataRow<*>>.colGroup(index: Int): SingleColumn<DataRow<C>> =
this
.ensureIsColumnGroup()
this.ensureIsColumnGroup()
.allColumnsInternal()
.getAt(index)
.cast<DataRow<C>>()
Expand Down
13 changes: 6 additions & 7 deletions core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/cols.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1091,14 +1091,13 @@ public interface ColsColumnsSelectionDsl<out _UNUSED> {
}

internal fun SingleColumn<DataRow<*>>.colsInternal(refs: Iterable<ColumnReference<*>>): ColumnSet<*> =
ensureIsColumnGroup()
.transformSingle { col ->
refs.map {
col.getCol(it) ?: throw IllegalArgumentException(
"Column at ${col.path.plus(it.path()).joinToString()} was not found.",
)
}
ensureIsColumnGroup().transformSingle { col ->
refs.map {
col.getCol(it) ?: throw IllegalArgumentException(
"Column at ${col.path.plus(it.path()).joinToString()} was not found.",
)
}
}

/**
* If this [ColumnsResolver] is a [SingleColumn], it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ public interface ColsOfKindColumnsSelectionDsl {
internal fun ColumnsResolver<*>.columnsOfKindInternal(
kinds: Set<ColumnKind>,
filter: ColumnFilter<*>,
): TransformableColumnSet<*> =
colsInternal {
it.kind() in kinds && filter(it)
}
): TransformableColumnSet<*> = colsInternal { it.kind() in kinds && filter(it) }

// endregion
Loading

0 comments on commit 0a4636a

Please sign in to comment.