Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KDocs start using Doc Preprocessor Gradle plugin #214

Merged
merged 55 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
e935502
added jcp support
Jolanrensen Dec 28, 2022
fcbbf8e
added sample/test for reusable comments in add.kt
Jolanrensen Dec 28, 2022
1c1fefe
jcp now only gets parsed for building the jar!
Jolanrensen Dec 28, 2022
12af079
updated examples
Jolanrensen Dec 29, 2022
e4442fe
now using kdocIncludeGradlePlugin
Jolanrensen Jan 18, 2023
da0be85
now using kdocIncludeGradlePlugin
Jolanrensen Jan 18, 2023
d7dd6bc
upgraded to docProcessor
Jolanrensen Jan 23, 2023
1db3e55
Merge branch 'master' into jpc-kdoc-reuse
Jolanrensen Jan 23, 2023
c017319
removed add again, fixed some small thing
Jolanrensen Jan 23, 2023
63ccc29
started on example doc structure using doc processor
Jolanrensen Jan 24, 2023
9708732
starting with update operation as template to figure out where to go …
Jolanrensen Jan 26, 2023
fdda5ba
renamed Column to AnyColumnReference, similar to AnyFrame.
Jolanrensen Jan 30, 2023
9ec93b4
continuing with kdocs with updated processor
Jolanrensen Feb 1, 2023
09da9b6
continuing with kdocs
Jolanrensen Feb 2, 2023
f87819e
gather.where now uses RowValueFilter instead of Predicate, similar to…
Jolanrensen Feb 5, 2023
005e11d
wip update documentation
Jolanrensen Feb 5, 2023
1db9d70
working on docs, found bug in kdoc highlighting
Jolanrensen Feb 7, 2023
a7a4b1b
row expressions and updating docs
Jolanrensen Feb 8, 2023
394a795
refactored examples separate from docs, working on update overloads docs
Jolanrensen Feb 8, 2023
83cfa31
final update overloads, fillNA and NA/NaN info
Jolanrensen Feb 9, 2023
28b1df9
slight refactoring and updated gradle plugin
Jolanrensen Feb 10, 2023
f70f0bc
added ColumnExpression typealias and uses across the api.
Jolanrensen Feb 14, 2023
428cff3
created stubs for columnExpression and dataframeexpression
Jolanrensen Feb 14, 2023
6ff4176
small refactorings and renaming
Jolanrensen Feb 17, 2023
fd1e545
notNull, dataframe expression, refactoring
Jolanrensen Feb 20, 2023
a795a9d
refactoring
Jolanrensen Feb 20, 2023
e9f7fd0
fixed some rendering issues
Jolanrensen Feb 21, 2023
d6c5f1b
refactoring
Jolanrensen Feb 21, 2023
2c2a610
updated doc processor plugin
Jolanrensen Feb 21, 2023
eeb36c0
updating doc processor plugin
Jolanrensen Feb 22, 2023
aa311a4
reverted Column -> AnyColumnReference to not clog up the PR
Jolanrensen Feb 22, 2023
341da80
refactored and renamed some of the general docs
Jolanrensen Feb 22, 2023
87710c1
docs and examples for ColumnExpression, links for SelectingColumns, d…
Jolanrensen Feb 23, 2023
03c398f
per row col. update.kt finished!
Jolanrensen Feb 23, 2023
15026b7
updated doc processor gradle plugin
Jolanrensen Feb 24, 2023
91e9754
cleaning PR a bit and added new target folder with generated sources
Jolanrensen Feb 27, 2023
91c9e8e
added generated sources with docs. Do we want to do it like this?
Jolanrensen Feb 27, 2023
265c587
removed commented-out code
Jolanrensen Mar 1, 2023
8ed0907
updated plugin
Jolanrensen Mar 2, 2023
61e01c8
updated plugin, fixes newlines and links in @include
Jolanrensen Mar 3, 2023
f40a021
Merge branch 'master' into jpc-kdoc-reuse
Jolanrensen Mar 14, 2023
0849309
updating docs plugin
Jolanrensen Mar 14, 2023
fb22326
ExpressionsGivenRowAndColumn
Jolanrensen Mar 14, 2023
d289e86
updating doc processor plugin and fixing linter
Jolanrensen Mar 15, 2023
490ecdd
docs for dropNulls
Jolanrensen Mar 16, 2023
b87085d
Merge branch 'master' into jpc-kdoc-reuse
Jolanrensen Mar 20, 2023
cfa9b4a
remaining docs for Nulls.kt
Jolanrensen Mar 20, 2023
70d167d
Merge branch 'master' into jpc-kdoc-reuse
Jolanrensen Mar 23, 2023
5d79b45
post master merge, small update and rendering docs
Jolanrensen Mar 23, 2023
1a467b9
updated settings.gradle.kts to master version
Jolanrensen Mar 23, 2023
f0e8c13
fixing linting
Jolanrensen Mar 24, 2023
e6ab95b
fixing some review issues
Jolanrensen Mar 27, 2023
2a1b305
including test sources to doc processor to enable cross-references
Jolanrensen Mar 27, 2023
234be05
Merge branch 'master' into jpc-kdoc-reuse
Jolanrensen Mar 27, 2023
3aa5f22
final update from master
Jolanrensen Mar 27, 2023
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
9 changes: 6 additions & 3 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ val addGeneratedSourcesToGit by tasks.creating(GitTask::class) {

// Backup the kotlin source files location
val kotlinMainSources = kotlin.sourceSets.main.get().kotlin.sourceDirectories
val kotlinTestSources = kotlin.sourceSets.test.get().kotlin.sourceDirectories

// Task to generate the processed documentation
val processKDocsMain by creatingProcessDocTask(
sources = kotlinMainSources.filterNot { "build/generated" in it.path }, // Exclude generated sources
sources = (kotlinMainSources + kotlinTestSources) // Include both test and main sources for cross-referencing
.filterNot { "build/generated" in it.path }, // Exclude generated sources
) {
target = file(generatedSourcesFolderName)
processors = listOf(
Expand Down Expand Up @@ -107,8 +109,9 @@ tasks.withType<Jar> {
doFirst {
kotlin.sourceSets.main {
kotlin.setSrcDirs(
processKDocsMain.targets +
kotlinMainSources.filter { "build/generated" in it.path } // Include generated sources (which were excluded above)
processKDocsMain.targets
.filterNot { "src/test/kotlin" in it.path || "src/test/java" in it.path } // filter out test sources again
.plus(kotlinMainSources.filter { "build/generated" in it.path }) // Include generated sources (which were excluded above)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ public typealias RowValueExpression<T, C, R> = DataRow<T>.(it: C) -> R
*/
public typealias RowColumnExpression<T, C, R> = (row: DataRow<T>, col: DataColumn<C>) -> R

/**
* [ColumnExpression] is used to express or select any instance of `R` using the given instance of [DataColumn]`<C>` as
* `this` and `it`.
*
* Shorthand for:
* ```kotlin
* DataColumn<C>.(it: DataColumn<C>) -> R
* ```
*/
public typealias ColumnExpression<C, R> = Selector<DataColumn<C>, R>

/**
* [ColumnSelector] is used to express or select a single column, represented by [SingleColumn]`<C>`, using the
* context of [ColumnsSelectionDsl]`<T>` as `this` and `it`.
Expand Down
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file I just started with, will probably work on docs after this PR is merged in a separate branch

Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,27 @@ import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.Predicate
import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
import org.jetbrains.kotlinx.dataframe.columns.ColumnResolutionContext
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
import org.jetbrains.kotlinx.dataframe.columns.renamedReference
import org.jetbrains.kotlinx.dataframe.columns.*
import org.jetbrains.kotlinx.dataframe.documentation.AccessApi
import org.jetbrains.kotlinx.dataframe.hasNulls
import org.jetbrains.kotlinx.dataframe.impl.columnName
import org.jetbrains.kotlinx.dataframe.impl.columns.ColumnsList
import org.jetbrains.kotlinx.dataframe.impl.columns.DistinctColumnSet
import org.jetbrains.kotlinx.dataframe.impl.columns.addPath
import org.jetbrains.kotlinx.dataframe.impl.columns.allColumnsExcept
import org.jetbrains.kotlinx.dataframe.impl.columns.changePath
import org.jetbrains.kotlinx.dataframe.impl.columns.createColumnSet
import org.jetbrains.kotlinx.dataframe.impl.columns.getAt
import org.jetbrains.kotlinx.dataframe.impl.columns.getChildrenAt
import org.jetbrains.kotlinx.dataframe.impl.columns.single
import org.jetbrains.kotlinx.dataframe.impl.columns.toColumns
import org.jetbrains.kotlinx.dataframe.impl.columns.top
import org.jetbrains.kotlinx.dataframe.impl.columns.transform
import org.jetbrains.kotlinx.dataframe.impl.columns.transformSingle
import org.jetbrains.kotlinx.dataframe.impl.columns.*
import org.jetbrains.kotlinx.dataframe.impl.columns.tree.dfs
import kotlin.reflect.KProperty
import kotlin.reflect.KType
import kotlin.reflect.typeOf

/**
* Referring to a column in the selection DSL can be done in several ways corresponding to all
* [Access APIs][AccessApi]:
* TODO: [Issue #286](https://github.com/Kotlin/dataframe/issues/286)
*/
private interface CommonColumnSelectionExamples

/** [Column Selection DSL][ColumnSelectionDsl] */
internal interface ColumnSelectionDslLink

/** TODO: [Issue #286](https://github.com/Kotlin/dataframe/issues/286) */
public interface ColumnSelectionDsl<out T> : ColumnsContainer<T> {

public operator fun <C> ColumnReference<C>.invoke(): DataColumn<C> = get(this)
Expand All @@ -56,6 +47,10 @@ public interface ColumnSelectionDsl<out T> : ColumnsContainer<T> {
public operator fun String.get(column: String): ColumnPath = pathOf(this, column)
}

/** [Columns Selection DSL][ColumnsSelectionDsl] */
internal interface ColumnsSelectionDslLink

/** TODO: [Issue #286](https://github.com/Kotlin/dataframe/issues/286) */
public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColumn<DataRow<T>> {

public fun <C> ColumnSet<C>.first(condition: ColumnFilter<C>): SingleColumn<C> =
Expand All @@ -70,24 +65,26 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum

public fun ColumnsContainer<*>.group(name: String): ColumnGroupReference = name.toColumnOf()

public operator fun String.rangeTo(endInclusive: String): ColumnSet<*> = toColumnAccessor().rangeTo(endInclusive.toColumnAccessor())

public operator fun AnyColumnReference.rangeTo(endInclusive: AnyColumnReference): ColumnSet<*> = object : ColumnSet<Any?> {
override fun resolve(context: ColumnResolutionContext): List<ColumnWithPath<Any?>> {
val startPath = [email protected](context)!!.path
val endPath = endInclusive.resolveSingle(context)!!.path
val parentPath = startPath.parent()!!
require(parentPath == endPath.parent()) { "Start and end columns have different parent column paths" }
val parentCol = context.df.getColumnGroup(parentPath)
val startIndex = parentCol.getColumnIndex(startPath.name)
val endIndex = parentCol.getColumnIndex(endPath.name)
return (startIndex..endIndex).map {
parentCol.getColumn(it).let {
it.addPath(parentPath + it.name)
public operator fun String.rangeTo(endInclusive: String): ColumnSet<*> =
toColumnAccessor().rangeTo(endInclusive.toColumnAccessor())

public operator fun AnyColumnReference.rangeTo(endInclusive: AnyColumnReference): ColumnSet<*> =
object : ColumnSet<Any?> {
override fun resolve(context: ColumnResolutionContext): List<ColumnWithPath<Any?>> {
val startPath = [email protected](context)!!.path
val endPath = endInclusive.resolveSingle(context)!!.path
val parentPath = startPath.parent()!!
require(parentPath == endPath.parent()) { "Start and end columns have different parent column paths" }
val parentCol = context.df.getColumnGroup(parentPath)
val startIndex = parentCol.getColumnIndex(startPath.name)
val endIndex = parentCol.getColumnIndex(endPath.name)
return (startIndex..endIndex).map {
parentCol.getColumn(it).let {
it.addPath(parentPath + it.name)
}
}
}
}
}

public fun none(): ColumnSet<*> = ColumnsList<Any?>(emptyList())

Expand Down Expand Up @@ -115,7 +112,8 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum

public fun <C> ColumnSet<DataRow<C>>.select(vararg columns: String): ColumnSet<*> = select { columns.toColumns() }

public fun <C, R> ColumnSet<DataRow<C>>.select(vararg columns: KProperty<R>): ColumnSet<R> = select { columns.toColumns() }
public fun <C, R> ColumnSet<DataRow<C>>.select(vararg columns: KProperty<R>): ColumnSet<R> =
select { columns.toColumns() }

public fun <C, R> ColumnSet<DataRow<C>>.select(selector: ColumnsSelector<C, R>): ColumnSet<R> = createColumnSet {
[email protected](it).flatMap { group ->
Expand Down Expand Up @@ -145,7 +143,8 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum

// region allDfs

public fun ColumnSet<*>.allDfs(includeGroups: Boolean = false): ColumnSet<Any?> = if (includeGroups) dfs { true } else dfs { !it.isColumnGroup() }
public fun ColumnSet<*>.allDfs(includeGroups: Boolean = false): ColumnSet<Any?> =
if (includeGroups) dfs { true } else dfs { !it.isColumnGroup() }

public fun String.allDfs(includeGroups: Boolean = false): ColumnSet<Any?> = toColumnAccessor().allDfs(includeGroups)

Expand Down Expand Up @@ -242,7 +241,9 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum

public fun <C> col(property: KProperty<C>): ColumnAccessor<C> = property.toColumnAccessor()

public operator fun ColumnSet<*>.get(colName: String): ColumnSet<Any?> = transform { it.mapNotNull { it.getChild(colName) } }
public operator fun ColumnSet<*>.get(colName: String): ColumnSet<Any?> =
transform { it.mapNotNull { it.getChild(colName) } }

public operator fun <C> ColumnSet<*>.get(column: ColumnReference<C>): ColumnSet<C> = cols(column)

public fun SingleColumn<AnyRow>.take(n: Int): ColumnSet<*> = transformSingle { it.children().take(n) }
Expand Down Expand Up @@ -288,8 +289,11 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
public infix fun <C> ColumnReference<C>.into(column: KProperty<*>): ColumnReference<C> = named(column.columnName)

public infix fun String.into(newName: String): ColumnReference<Any?> = toColumnAccessor().into(newName)
public infix fun String.into(column: ColumnAccessor<*>): ColumnReference<Any?> = toColumnAccessor().into(column.name())
public infix fun String.into(column: KProperty<*>): ColumnReference<Any?> = toColumnAccessor().into(column.columnName)
public infix fun String.into(column: ColumnAccessor<*>): ColumnReference<Any?> =
toColumnAccessor().into(column.name())

public infix fun String.into(column: KProperty<*>): ColumnReference<Any?> =
toColumnAccessor().into(column.columnName)

public infix fun <C> ColumnReference<C>.named(newName: String): ColumnReference<C> = renamedReference(newName)
public infix fun <C> ColumnReference<C>.named(name: KProperty<*>): ColumnReference<C> = named(name.columnName)
Expand All @@ -311,6 +315,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
public infix fun <C> KProperty<C>.and(other: String): ColumnSet<Any?> = toColumnAccessor() and other
public infix fun <C> KProperty<C>.and(other: KProperty<C>): ColumnSet<C> =
toColumnAccessor() and other.toColumnAccessor()

public infix fun <C> KProperty<C>.and(other: ColumnsSelector<T, C>): ColumnSet<C> = toColumnAccessor() and other()

// endregion
Expand Down Expand Up @@ -339,7 +344,7 @@ public interface ColumnsSelectionDsl<out T> : ColumnSelectionDsl<T>, SingleColum
public inline fun <T, reified R> ColumnsSelectionDsl<T>.expr(
name: String = "",
infer: Infer = Infer.Nulls,
noinline expression: AddExpression<T, R>
noinline expression: AddExpression<T, R>,
): DataColumn<R> = mapToColumn(name, infer, expression)

internal fun <T, C> ColumnsSelector<T, C>.filter(predicate: (ColumnWithPath<C>) -> Boolean): ColumnsSelector<T, C> =
Expand Down
Loading