@@ -3,6 +3,8 @@ package org.jetbrains.kotlinx.dataframe.api
33import org.jetbrains.kotlinx.dataframe.AnyFrame
44import org.jetbrains.kotlinx.dataframe.ColumnsSelector
55import org.jetbrains.kotlinx.dataframe.DataFrame
6+ import org.jetbrains.kotlinx.dataframe.RowColumnExpression
7+ import org.jetbrains.kotlinx.dataframe.RowValueExpression
68import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
79import org.jetbrains.kotlinx.dataframe.annotations.HasSchema
810import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
@@ -14,20 +16,114 @@ import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
1416import org.jetbrains.kotlinx.dataframe.columns.renamedReference
1517import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
1618import org.jetbrains.kotlinx.dataframe.documentation.AccessApiLink
19+ import org.jetbrains.kotlinx.dataframe.documentation.DocumentationUrls
20+ import org.jetbrains.kotlinx.dataframe.documentation.DslGrammarLink
1721import 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
1826import org.jetbrains.kotlinx.dataframe.impl.api.renameImpl
1927import org.jetbrains.kotlinx.dataframe.impl.columnName
2028import org.jetbrains.kotlinx.dataframe.impl.toCamelCaseByDelimiters
2129import 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" )
27112public 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" )
32128public fun <T , C > DataFrame<T>.rename (columns : ColumnsSelector <T , C >): RenameClause <T , C > = RenameClause (this , columns)
33129
0 commit comments