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

Documentation for replaceAll #738

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import org.jetbrains.kotlinx.dataframe.api.remove
import org.jetbrains.kotlinx.dataframe.api.rename
import org.jetbrains.kotlinx.dataframe.api.reorder
import org.jetbrains.kotlinx.dataframe.api.replace
import org.jetbrains.kotlinx.dataframe.api.replaceAll
import org.jetbrains.kotlinx.dataframe.api.reverse
import org.jetbrains.kotlinx.dataframe.api.schema
import org.jetbrains.kotlinx.dataframe.api.select
Expand Down Expand Up @@ -174,6 +175,18 @@ class Modify : TestBase() {
// SampleEnd
}

@Test
@TransformDataFrameExpressions
fun replaceAll() {
// SampleStart
functions.replaceAll(
"DataFrame<*>" to "DataFrame",
"DataRow<*>" to "DataRow",
"AnyRow" to "DataRow",
) { receiverType and returnType }
// SampleEnd
}

@Test
@TransformDataFrameExpressions
fun convert() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jetbrains.kotlinx.dataframe.samples.api
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
import org.jetbrains.kotlinx.dataframe.api.asColumnGroup
Expand All @@ -18,6 +19,7 @@ import org.jetbrains.kotlinx.dataframe.api.to
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
import org.jetbrains.kotlinx.dataframe.explainer.PluginCallbackProxy
import org.jetbrains.kotlinx.dataframe.impl.columns.asValueColumn
import org.jetbrains.kotlinx.dataframe.io.readJsonStr
import org.junit.After
import org.junit.Before

Expand Down Expand Up @@ -108,6 +110,113 @@ public open class TestBase {

infix fun <T, U : T> T.willBe(expected: U?) = shouldBe(expected)

@DataSchema
interface Functions {
val receiverType: String
val name: String
val parameters: List<String>
val returnType: String
}

val functions = DataFrame.readJsonStr("""
[{
"receiverType": "DataRow<*>",
"name": "rowStd",
"parameters": ["skipNA: Boolean = skipNA_default", "ddof: Int = ddof_default"],
"returnType": "Double"
}, {
"receiverType": "DataRow<*>",
"name": "rowStdOf",
"parameters": ["ddof: Int = ddof_default"],
"returnType": "Double"
}, {
"receiverType": "DataFrame",
"name": "stdFor",
"parameters": ["skipNA: Boolean = skipNA_default", "ddof: Int = ddof_default", "columns: ColumnsForAggregateSelector<T, Number?>"],
"returnType": "DataRow"
}, {
"receiverType": "DataFrame",
"name": "replace",
"parameters": ["columns: ColumnsSelector<T, C>"],
"returnType": "ReplaceClause"
}, {
"receiverType": "DataFrame",
"name": "copy",
"parameters": [],
"returnType": "DataFrame"
},{
"receiverType": "AnyRow",
"name": "transposeTo",
"parameters": [],
"returnType": "DataFrame"
}, {
"receiverType": "DataFrame",
"name": "tail",
"parameters": ["numRows: Int = 5"],
"returnType": "DataFrame"
}, {
"receiverType": "DataFrame",
"name": "mapToFrame",
"parameters": ["body: AddDsl<T>.() -> Unit"],
"returnType": "AnyFrame"
}, {
"receiverType": "DataFrame",
"name": "asGroupBy",
"parameters": ["groupedColumnName: String"],
"returnType": "GroupBy"
}, {
"receiverType": "DataFrame",
"name": "select",
"parameters": ["columns: ColumnsSelector<T, *>"],
"returnType": "DataFrame"
}, {
"receiverType": "DataFrame",
"name": "split",
"parameters": ["columns: ColumnsSelector<T, C?>"],
"returnType": "Split"
}, {
"receiverType": "DataRow<*>",
"name": "allNA",
"parameters": [],
"returnType": "Boolean"
}, {
"receiverType": "DataRow<*>",
"name": "rowMean",
"parameters": ["skipNA: Boolean = skipNA_default"],
"returnType": "Double"
}, {
"receiverType": "DataRow<*>",
"name": "rowMeanOf",
"parameters": [],
"returnType": "Double"
}, {
"receiverType": "DataFrame",
"name": "meanFor",
"parameters": ["skipNA: Boolean = skipNA_default", "columns: ColumnsForAggregateSelector<T, C?>"],
"returnType": "DataRow"
}, {
"receiverType": "DataFrame",
"name": "fillNulls",
"parameters": ["columns: ColumnsSelector<T, C?>"],
"returnType": "Update"
}, {
"receiverType": "DataFrame",
"name": "fillNaNs",
"parameters": ["columns: ColumnsSelector<T, C>"],
"returnType": "Update"
}, {
"receiverType": "DataFrame",
"name": "fillNA",
"parameters": ["columns: ColumnsSelector<T, C?>"],
"returnType": "Update"
}, {
"receiverType": "DataFrame<*>",
"name": "toListOf",
"parameters": [],
"returnType": "List<T>"
}]
""".trimIndent()).cast<Functions>(verify = true)

/**
* Asserts that all elements of the iterable are equal to each other
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import org.jetbrains.kotlinx.dataframe.api.remove
import org.jetbrains.kotlinx.dataframe.api.rename
import org.jetbrains.kotlinx.dataframe.api.reorder
import org.jetbrains.kotlinx.dataframe.api.replace
import org.jetbrains.kotlinx.dataframe.api.replaceAll
import org.jetbrains.kotlinx.dataframe.api.reverse
import org.jetbrains.kotlinx.dataframe.api.schema
import org.jetbrains.kotlinx.dataframe.api.select
Expand Down Expand Up @@ -174,6 +175,18 @@ class Modify : TestBase() {
// SampleEnd
}

@Test
@TransformDataFrameExpressions
fun replaceAll() {
// SampleStart
functions.replaceAll(
"DataFrame<*>" to "DataFrame",
"DataRow<*>" to "DataRow",
"AnyRow" to "DataRow",
) { receiverType and returnType }
// SampleEnd
}

@Test
@TransformDataFrameExpressions
fun convert() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.jetbrains.kotlinx.dataframe.samples.api
import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import org.jetbrains.kotlinx.dataframe.DataFrame
import org.jetbrains.kotlinx.dataframe.DataRow
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
import org.jetbrains.kotlinx.dataframe.api.asColumnGroup
Expand All @@ -18,6 +19,7 @@ import org.jetbrains.kotlinx.dataframe.api.to
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
import org.jetbrains.kotlinx.dataframe.explainer.PluginCallbackProxy
import org.jetbrains.kotlinx.dataframe.impl.columns.asValueColumn
import org.jetbrains.kotlinx.dataframe.io.readJsonStr
import org.junit.After
import org.junit.Before

Expand Down Expand Up @@ -108,6 +110,115 @@ public open class TestBase {

infix fun <T, U : T> T.willBe(expected: U?) = shouldBe(expected)

@DataSchema
interface Functions {
val receiverType: String
val name: String
val parameters: List<String>
val returnType: String
}

val functions = DataFrame.readJsonStr(
"""
[{
"receiverType": "DataRow<*>",
"name": "rowStd",
"parameters": ["skipNA: Boolean = skipNA_default", "ddof: Int = ddof_default"],
"returnType": "Double"
}, {
"receiverType": "DataRow<*>",
"name": "rowStdOf",
"parameters": ["ddof: Int = ddof_default"],
"returnType": "Double"
}, {
"receiverType": "DataFrame",
"name": "stdFor",
"parameters": ["skipNA: Boolean = skipNA_default", "ddof: Int = ddof_default", "columns: ColumnsForAggregateSelector<T, Number?>"],
"returnType": "DataRow"
}, {
"receiverType": "DataFrame",
"name": "replace",
"parameters": ["columns: ColumnsSelector<T, C>"],
"returnType": "ReplaceClause"
}, {
"receiverType": "DataFrame",
"name": "copy",
"parameters": [],
"returnType": "DataFrame"
},{
"receiverType": "AnyRow",
"name": "transposeTo",
"parameters": [],
"returnType": "DataFrame"
}, {
"receiverType": "DataFrame",
"name": "tail",
"parameters": ["numRows: Int = 5"],
"returnType": "DataFrame"
}, {
"receiverType": "DataFrame",
"name": "mapToFrame",
"parameters": ["body: AddDsl<T>.() -> Unit"],
"returnType": "AnyFrame"
}, {
"receiverType": "DataFrame",
"name": "asGroupBy",
"parameters": ["groupedColumnName: String"],
"returnType": "GroupBy"
}, {
"receiverType": "DataFrame",
"name": "select",
"parameters": ["columns: ColumnsSelector<T, *>"],
"returnType": "DataFrame"
}, {
"receiverType": "DataFrame",
"name": "split",
"parameters": ["columns: ColumnsSelector<T, C?>"],
"returnType": "Split"
}, {
"receiverType": "DataRow<*>",
"name": "allNA",
"parameters": [],
"returnType": "Boolean"
}, {
"receiverType": "DataRow<*>",
"name": "rowMean",
"parameters": ["skipNA: Boolean = skipNA_default"],
"returnType": "Double"
}, {
"receiverType": "DataRow<*>",
"name": "rowMeanOf",
"parameters": [],
"returnType": "Double"
}, {
"receiverType": "DataFrame",
"name": "meanFor",
"parameters": ["skipNA: Boolean = skipNA_default", "columns: ColumnsForAggregateSelector<T, C?>"],
"returnType": "DataRow"
}, {
"receiverType": "DataFrame",
"name": "fillNulls",
"parameters": ["columns: ColumnsSelector<T, C?>"],
"returnType": "Update"
}, {
"receiverType": "DataFrame",
"name": "fillNaNs",
"parameters": ["columns: ColumnsSelector<T, C>"],
"returnType": "Update"
}, {
"receiverType": "DataFrame",
"name": "fillNA",
"parameters": ["columns: ColumnsSelector<T, C?>"],
"returnType": "Update"
}, {
"receiverType": "DataFrame<*>",
"name": "toListOf",
"parameters": [],
"returnType": "List<T>"
}]
""".trimIndent()
).cast<Functions>(verify = true)

/**
* Asserts that all elements of the iterable are equal to each other
*/
Expand Down
Loading
Loading