Skip to content

Commit

Permalink
Automated commit of generated code
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Dec 12, 2024
1 parent 5c18bfd commit 8aee07c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import kotlin.reflect.KProperty
*
* Base interface for [DataFrame] and [ColumnSelectionDsl]
*
* @param T Schema marker. Used to generate extension properties for typed column access.
* @param T Schema marker. Used to resolve generated extension properties for typed column access.
*/
public interface ColumnsContainer<out T> {
public interface ColumnsContainer<out T> : ColumnsScope<T> {

// region columns

Expand Down Expand Up @@ -54,7 +54,7 @@ public interface ColumnsContainer<out T> {

// region get

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

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.jetbrains.kotlinx.dataframe

/**
* Provides minimal API required for generated column properties:
*
* `val ColumnsScope<Schema marker>.column: DataColumn<String> get() = this["column"] as DataColumn<String>`
*
* @param T Schema marker. Used to resolve generated extension properties for typed column access.
*/
public interface ColumnsScope<out T> {
public operator fun get(columnName: String): AnyCol
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.kotlinx.dataframe.AnyCol
import org.jetbrains.kotlinx.dataframe.AnyColumnReference
import org.jetbrains.kotlinx.dataframe.ColumnSelector
import org.jetbrains.kotlinx.dataframe.ColumnsContainer
import org.jetbrains.kotlinx.dataframe.ColumnsScope
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
Expand Down Expand Up @@ -58,6 +59,28 @@ public fun <T> ColumnsContainer<T>.getFrameColumn(columnName: String): FrameColu
public fun <T> ColumnsContainer<T>.getColumnGroup(columnPath: ColumnPath): ColumnGroup<*> =
get(columnPath).asColumnGroup()

/**
* Utility property to access scope with only dataframe column properties for code completion,
* filtering out DataFrame API.
*
* It's a quick way to check that code generation in notebooks or compiler plugin
* worked as expected or find columns you're interested in.
*
* In notebooks:
* ```
* val df = DataFrame.read("file.csv")
* ==== next code cell
* df. // column properties are mixed together with methods, not easy to find unless you already know names
* df.properties(). // easy to overview available columns
* ```
* In compiler plugin:
* ```
* val df = @Import DataFrame.read("file.csv")
* df.properties().
* ```
*/
public fun <T> DataFrame<T>.properties(): ColumnsScope<T> = this

// region getColumn

public fun <T> ColumnsContainer<T>.getColumn(name: String): AnyCol =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.jetbrains.dataframe.impl.codeGen.InterfaceGenerationMode.WithFields
import org.jetbrains.dataframe.keywords.HardKeywords
import org.jetbrains.dataframe.keywords.ModifierKeywords
import org.jetbrains.kotlinx.dataframe.ColumnsContainer
import org.jetbrains.kotlinx.dataframe.ColumnsScope
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
Expand Down Expand Up @@ -166,7 +167,7 @@ internal object FullyQualifiedNames : TypeRenderingStrategy {
internal object ShortNames : TypeRenderingStrategy {

private val dataRow = DataRow::class.simpleName!!
private val columnsContainer = ColumnsContainer::class.simpleName!!
private val columnsContainer = ColumnsScope::class.simpleName!!
private val dataFrame = DataFrame::class.simpleName!!
private val dataColumn = DataColumn::class.simpleName!!
private val columnGroup = ColumnGroup::class.simpleName!!
Expand Down Expand Up @@ -565,7 +566,7 @@ public fun Code.toStandaloneSnippet(packageName: String, additionalImports: List
appendLine("package $packageName")
appendLine()
}
appendLine("import org.jetbrains.kotlinx.dataframe.ColumnsContainer")
appendLine("import org.jetbrains.kotlinx.dataframe.ColumnsScope")
appendLine("import org.jetbrains.kotlinx.dataframe.DataColumn")
appendLine("import org.jetbrains.kotlinx.dataframe.DataFrame")
appendLine("import org.jetbrains.kotlinx.dataframe.DataRow")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,11 @@ internal fun DataFrameHtmlData.print() = println(this)
/**
* By default, cell content is formatted as text
* Use [RenderedContent.media] or [IMG], [IFRAME] if you need custom HTML inside a cell.
* @return DataFrameHtmlData with table script and css definitions. Can be saved as an *.html file and displayed in the browser
*
* The [DataFrameHtmlData] be saved as an *.html file and displayed in the browser.
* If you save it as a file and find it in the project tree,
* the ["Open in browser"](https://www.jetbrains.com/help/idea/editing-html-files.html#ws_html_preview_output_procedure) feature of IntelliJ IDEA will automatically reload the file content when it's updated
* @return DataFrameHtmlData with table script and css definitions
*/
public fun <T> DataFrame<T>.toStandaloneHTML(
configuration: DisplayConfiguration = DisplayConfiguration.DEFAULT,
Expand Down Expand Up @@ -620,10 +624,18 @@ public data class DataFrameHtmlData(
destination.writeText(toString())
}

public fun writeHTML(destination: String) {
File(destination).writeText(toString())
}

public fun writeHTML(destination: Path) {
destination.writeText(toString())
}

/**
* Opens a new tab in your default browser.
* Consider [writeHTML] with the [HTML file auto-reload](https://www.jetbrains.com/help/idea/editing-html-files.html#ws_html_preview_output_procedure) feature of IntelliJ IDEA if you want to experiment with the output and run program multiple times
*/
public fun openInBrowser() {
val file = File.createTempFile("df_rendering", ".html")
writeHTML(file)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.jetbrains.dataframe.impl.codeGen.InterfaceGenerationMode
import org.jetbrains.dataframe.impl.codeGen.ReplCodeGenerator
import org.jetbrains.dataframe.impl.codeGen.generate
import org.jetbrains.kotlinx.dataframe.AnyRow
import org.jetbrains.kotlinx.dataframe.ColumnsContainer
import org.jetbrains.kotlinx.dataframe.ColumnsScope
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.api.dataFrameOf
Expand All @@ -30,7 +30,7 @@ class CodeGenerationTests : BaseTest() {

val personShortName = Person::class.simpleName!!

val dfName = (ColumnsContainer::class).simpleName!!
val dfName = (ColumnsScope::class).simpleName!!
val dfRowName = (DataRow::class).simpleName!!
val dataCol = (DataColumn::class).simpleName!!
val dataRow = (DataRow::class).simpleName!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.string.shouldNotBeEmpty
import org.jetbrains.dataframe.impl.codeGen.ReplCodeGenerator
import org.jetbrains.dataframe.impl.codeGen.process
import org.jetbrains.kotlinx.dataframe.ColumnsContainer
import org.jetbrains.kotlinx.dataframe.ColumnsScope
import org.jetbrains.kotlinx.dataframe.DataColumn
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
Expand All @@ -20,7 +20,7 @@ import org.junit.Test
@Suppress("ktlint:standard:class-naming")
class ReplCodeGenTests : BaseTest() {

val dfName = (ColumnsContainer::class).simpleName!!
val dfName = (ColumnsScope::class).simpleName!!
val dfRowName = (DataRow::class).simpleName!!
val dataCol = (DataColumn::class).simpleName!!
val intName = Int::class.simpleName!!
Expand Down Expand Up @@ -192,7 +192,7 @@ class ReplCodeGenTests : BaseTest() {
repl.process<Test3.B>()
repl.process<Test3.D>()
val c = repl.process(Test3.df, Test3::df)
"""val .*ColumnsContainer<\w*>.x:""".toRegex().findAll(c.declarations).count() shouldBe 1
"""val .*ColumnsScope<\w*>.x:""".toRegex().findAll(c.declarations).count() shouldBe 1
}

object Test4 {
Expand All @@ -216,6 +216,6 @@ class ReplCodeGenTests : BaseTest() {
repl.process<Test4.A>()
repl.process<Test4.B>()
val c = repl.process(Test4.df, Test4::df)
"""val .*ColumnsContainer<\w*>.a:""".toRegex().findAll(c.declarations).count() shouldBe 1
"""val .*ColumnsScope<\w*>.a:""".toRegex().findAll(c.declarations).count() shouldBe 1
}
}

0 comments on commit 8aee07c

Please sign in to comment.