Skip to content

Commit 66280bb

Browse files
rename kdcos init
1 parent 6ee612c commit 66280bb

File tree

3 files changed

+100
-1
lines changed

3 files changed

+100
-1
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/convert.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ internal interface ConvertDocs {
128128
* {@include [DslGrammarLink]}
129129
* {@include [LineBreak]}
130130
*
131-
* **[`convert`][convert]**` { columnsSelector: `[`ColumnsSelector`][ColumnsSelector]` }`
131+
* **[`convert`][DataFrame.convert]**` { columnsSelector: `[`ColumnsSelector`][ColumnsSelector]` }`
132132
*
133133
* {@include [Indent]}
134134
* __`.`__[**`with`**][Convert.with]`(infer: `[`Infer`][Infer]`, rowExpression: `[`RowValueExpression`][RowValueExpression]`)`

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/rename.kt

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package org.jetbrains.kotlinx.dataframe.api
33
import org.jetbrains.kotlinx.dataframe.AnyFrame
44
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
55
import org.jetbrains.kotlinx.dataframe.DataFrame
6+
import org.jetbrains.kotlinx.dataframe.RowColumnExpression
7+
import org.jetbrains.kotlinx.dataframe.RowValueExpression
68
import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
79
import org.jetbrains.kotlinx.dataframe.annotations.HasSchema
810
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
@@ -14,20 +16,114 @@ import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
1416
import org.jetbrains.kotlinx.dataframe.columns.renamedReference
1517
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
1618
import org.jetbrains.kotlinx.dataframe.documentation.AccessApiLink
19+
import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls
20+
import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarLink
1721
import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarTemplateColumnsSelectionDsl.DslGrammarTemplate
22+
import org.jetbrains.kotlinx.dataframe.documentation.ExcludeFromSources
23+
import org.jetbrains.kotlinx.dataframe.documentation.Indent
24+
import org.jetbrains.kotlinx.dataframe.documentation.LineBreak
25+
import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
1826
import org.jetbrains.kotlinx.dataframe.impl.api.renameImpl
1927
import org.jetbrains.kotlinx.dataframe.impl.columnName
2028
import org.jetbrains.kotlinx.dataframe.impl.toCamelCaseByDelimiters
2129
import kotlin.reflect.KProperty
30+
import kotlin.reflect.KType
2231

2332
// region DataFrame
2433

34+
/**
35+
* Renames the specified [columns\] their original values and location within the [DataFrame].
36+
*
37+
* This function does not immediately convert the columns but instead selects columns to convert and
38+
* returns a [RenameClause],
39+
* which serves as an intermediate step.
40+
* The [RenameClause] object provides methods to transform selected columns using:
41+
* - [into(name)][RenameClause.into]
42+
* - [into { nameExpression }][RenameClause.into]
43+
* - [toCamelCase()][RenameClause.toCamelCase]
44+
*
45+
* Each method returns a new [DataFrame] with the renamed columns.
46+
*
47+
* Check out [Grammar].
48+
*
49+
* @include [SelectingColumns.ColumnGroupsAndNestedColumnsMention]
50+
*
51+
* See [Selecting Columns][RenameSelectingOptions].
52+
*
53+
* For more information: {@include [DocumentationUrls.Rename]}
54+
*/
55+
internal interface RenameDocs {
56+
57+
/**
58+
* {@comment Version of [SelectingColumns] with correctly filled in examples}
59+
* @include [SelectingColumns] {@include [SetRenameOperationArg]}
60+
*/
61+
interface RenameSelectingOptions
62+
63+
64+
/**
65+
* ## Rename Operation Grammar
66+
* {@include [LineBreak]}
67+
* {@include [DslGrammarLink]}
68+
* {@include [LineBreak]}
69+
*
70+
* **[`rename`][rename]**` { columnsSelector: `[`ColumnsSelector`][ColumnsSelector]` }`
71+
*
72+
* {@include [Indent]}
73+
* `| `__`.`__[**`into`**][RenameClause.into]`(name: `[`String`][String]`)`
74+
*
75+
* {@include [Indent]}
76+
* `| `__`.`__[**`into`**][RenameClause.into]` { nameExpression: (`[`ColumnWithPath`][ColumnWithPath]`<C>) -> `[String]` }`
77+
*
78+
* {@include [Indent]}
79+
* `| `__`.`__[**`toCamelCase`**][RenameClause.toCamelCase]`()`
80+
*/
81+
interface Grammar
82+
}
83+
84+
/** {@set [SelectingColumns.OPERATION] [rename][rename]} */
85+
@ExcludeFromSources
86+
private interface SetRenameOperationArg
87+
88+
/**
89+
* {@include [RenameDocs]}
90+
* ### This Rename Overload
91+
*/
92+
@ExcludeFromSources
93+
private interface CommonRenameDocs
94+
95+
/**
96+
* Renames columns in the [DataFrame].
97+
*
98+
* This function allows renaming multiple columns in a single call by supplying a list of name pairs.
99+
* Each pair consists of the current column name and the desired new name.
100+
*
101+
* Example:
102+
* ```
103+
* df.rename("oldName1" to "newName1", "oldName2" to "newName2")
104+
* ```
105+
*
106+
* @param mappings A vararg of pairs where each pair consists of the original column name (`first`)
107+
* and the new column name (`second`).
108+
* @return A new [DataFrame] with the renamed columns.
109+
*/
25110
@Refine
26111
@Interpretable("RenameMapping")
27112
public fun <T> DataFrame<T>.rename(vararg mappings: Pair<String, String>): DataFrame<T> =
28113
rename { mappings.map { it.first.toColumnAccessor() }.toColumnSet() }
29114
.into(*mappings.map { it.second }.toTypedArray())
30115

116+
/**
117+
* @include [CommonRenameDocs]
118+
* @include [SelectingColumns.Dsl] {@include [SetRenameOperationArg]}
119+
* ### Examples:
120+
* ```kotlin
121+
* df.rename { oldName }.into("newName")
122+
* df.convert { colsAtAnyDepth() }.into { it.path.joinToString("->") }
123+
* df.rename { cols { it.name.contains(".") } }.into { it.path.joinToString("->") }
124+
* ```
125+
* @param [columns\] The [Columns Selector][ColumnsSelector] used to select the columns of this [DataFrame] to group.
126+
*/
31127
@Interpretable("Rename")
32128
public fun <T, C> DataFrame<T>.rename(columns: ColumnsSelector<T, C>): RenameClause<T, C> = RenameClause(this, columns)
33129

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/documentation/DocumentationUrls.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,7 @@ internal interface DocumentationUrls {
101101

102102
/** [See `convert` on the documentation website.]({@include [Url]}/convert.html) */
103103
interface Convert
104+
105+
/** [See `rename` on the documentation website.]({@include [Url]}/rename.html) */
106+
interface Rename
104107
}

0 commit comments

Comments
 (0)