@@ -3,8 +3,6 @@ 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
86import org.jetbrains.kotlinx.dataframe.annotations.AccessApiOverload
97import org.jetbrains.kotlinx.dataframe.annotations.HasSchema
108import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
@@ -28,20 +26,20 @@ import org.jetbrains.kotlinx.dataframe.impl.columnName
2826import org.jetbrains.kotlinx.dataframe.impl.toCamelCaseByDelimiters
2927import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
3028import kotlin.reflect.KProperty
31- import kotlin.reflect.KType
3229
3330// region DataFrame
3431
3532/* *
36- * Renames the specified [columns\] their original values and location within the [DataFrame].
33+ * Renames the specified [columns\] keeping their original values and location within the [DataFrame].
3734 *
38- * This function does not immediately convert the columns but instead selects columns to convert and
35+ * This function does not immediately rename the columns but instead selects columns to rename and
3936 * returns a [RenameClause],
4037 * which serves as an intermediate step.
41- * The [RenameClause] object provides methods to transform selected columns using:
42- * - [into(name)][RenameClause.into]
43- * - [into { nameExpression }][RenameClause.into]
44- * - [toCamelCase()][RenameClause.toCamelCase]
38+ * The [RenameClause] object provides methods to rename selected columns using:
39+ * - [into(name)][RenameClause.into] - renames selected columns to the specified names.
40+ * - [into { nameExpression }][RenameClause.into] - renames selected columns using a provided
41+ * expression assuming column with its path and returning a new name.
42+ * - [toCamelCase()][RenameClause.toCamelCase] - renames all selected columns to "camelCase".
4543 *
4644 * Each method returns a new [DataFrame] with the renamed columns.
4745 *
@@ -61,7 +59,6 @@ internal interface RenameDocs {
6159 */
6260 interface RenameSelectingOptions
6361
64-
6562 /* *
6663 * ## Rename Operation Grammar
6764 * {@include [LineBreak]}
@@ -119,9 +116,14 @@ public fun <T> DataFrame<T>.rename(vararg mappings: Pair<String, String>): DataF
119116 * @include [SelectingColumns.Dsl] {@include [SetRenameOperationArg]}
120117 * ### Examples:
121118 * ```kotlin
122- * df.rename { oldName }.into("newName")
123- * df.convert { colsAtAnyDepth() }.into { it.path.joinToString("->") }
124- * df.rename { cols { it.name.contains(".") } }.into { it.path.joinToString("->") }
119+ * // Rename "col1" to "width" and "col2" to "length"
120+ * df.rename { col1 and col2 }.into("width", "length")
121+ *
122+ * // Rename all columns using their full path, delimited by "->"
123+ * df.rename { colsAtAnyDepth() }.into { it.path.joinToString("->") }
124+ *
125+ * // Renames all numeric columns to "camelCase"
126+ * df.rename { colsOf<Number>() }.toCamelCase()
125127 * ```
126128 * @param [columns\] The [Columns Selector][ColumnsSelector] used to select the columns of this [DataFrame] to group.
127129 */
@@ -137,17 +139,47 @@ public fun <T, C> DataFrame<T>.rename(vararg cols: ColumnReference<C>): RenameCl
137139@AccessApiOverload
138140public fun <T , C > DataFrame<T>.rename (vararg cols : KProperty <C >): RenameClause <T , C > = rename { cols.toColumnSet() }
139141
142+ /* *
143+ * @include [CommonRenameDocs]
144+ * @include [SelectingColumns.ColumnNames] {@include [SetRenameOperationArg]}
145+ * ### Examples:
146+ * ```kotlin
147+ * // Rename "col1" to "width" and "col2" to "length"
148+ * df.rename("col1", "col2").into("width", "length")
149+ *
150+ * // Renames "arrival_date" and "passport-ID" columns to "camelCase"
151+ * df.rename("arrival_date", "passport-ID").toCamelCase()
152+ * ```
153+ * @param [columns\] The [Columns Names][String] used to select the columns of this [DataFrame] to group.
154+ */
140155public fun <T > DataFrame<T>.rename (vararg cols : String ): RenameClause <T , Any ?> = rename { cols.toColumnSet() }
141156
157+ /* *
158+ * An intermediate class used in the [rename] operation.
159+ *
160+ * This class itself does not perform any renaming — it is a transitional step
161+ * before specifying how to rename the selected columns.
162+ * It must be followed by one of the renaming methods
163+ * to produce a new [DataFrame] with renamed columns.
164+ *
165+ * The resulting columns will keep their original values and positions
166+ * in the [DataFrame], but their names will be changed.
167+ *
168+ * Use the following methods to perform the conversion:
169+ * - [into(name)][RenameClause.into] — renames selected columns to the specified names.
170+ * - [into { nameExpression }][RenameClause.into] — renames selected columns using a custom expression,
171+ * which takes the column and its path and returns a new name.
172+ * - [toCamelCase()][RenameClause.toCamelCase] — renames all selected columns to `camelCase`.
173+ *
174+ * See [Grammar][RenameDocs.Grammar] for more details.
175+ */
142176@HasSchema(schemaArg = 0 )
143177public class RenameClause <T , C >(internal val df : DataFrame <T >, internal val columns : ColumnsSelector <T , C >) {
144178 override fun toString (): String = " RenameClause(df=$df , columns=$columns )"
145179}
146180
147181/* *
148- * ## Rename to "camelCase"
149- *
150- * This function renames all columns in this [DataFrame] to the "camelCase" format.
182+ * Renames all columns in this [DataFrame] to the "camelCase" format.
151183 *
152184 * Removes all delimiters between words and capitalizes each word except the first one.
153185 * Adds an underscore between consecutive numbers.
@@ -160,7 +192,7 @@ public class RenameClause<T, C>(internal val df: DataFrame<T>, internal val colu
160192 *
161193 * Returns a [DataFrame] with updated column names.
162194 *
163- * ### Examples:
195+ * ### Renaming Examples
164196 * ```
165197 * "snake_case_name" -> "snakeCaseName"
166198 * "PascalCaseName" -> "pascalCaseName"
@@ -189,6 +221,30 @@ public fun <T> DataFrame<T>.renameToCamelCase(): DataFrame<T> =
189221public fun <T , C > RenameClause <T , C >.into (vararg newColumns : ColumnReference <* >): DataFrame <T > =
190222 into(* newColumns.map { it.name() }.toTypedArray())
191223
224+ /* *
225+ * Renames the columns selected with [rename] to the specified [newNames],
226+ * preserving their values and positions within the [DataFrame].
227+ *
228+ * The mapping is positional: [newNames] are applied in the order
229+ * the columns were selected — the first selected column is renamed to the first name,
230+ * the second to the second, and so on.
231+ *
232+ * For more information: {@include [DocumentationUrls.Rename]}
233+ *
234+ * Check out [Grammar][RenameDocs.Grammar].
235+ *
236+ * ### Examples:
237+ * ```kotlin
238+ * // Rename "col1" to "width" and "col2" to "length"
239+ * df.rename("col1", "col2").into("width", "length")
240+ *
241+ * // Rename "col1" to "width" and "col2" to "length"
242+ * df.rename { col1 and col2 }.into("width", "length")
243+ * ```
244+ *
245+ * @param newNames The new names for the selected columns, applied in order of selecting.
246+ * @return A new [DataFrame] with the columns renamed.
247+ */
192248@Refine
193249@Interpretable(" RenameInto" )
194250public fun <T , C > RenameClause <T , C >.into (vararg newNames : String ): DataFrame <T > = renameImpl(newNames)
@@ -198,13 +254,35 @@ public fun <T, C> RenameClause<T, C>.into(vararg newNames: String): DataFrame<T>
198254public fun <T , C > RenameClause <T , C >.into (vararg newNames : KProperty <* >): DataFrame <T > =
199255 into(* newNames.map { it.name }.toTypedArray())
200256
257+ /* *
258+ * Renames the columns selected with [rename] by applying the [transform] expression
259+ * to each of them. This expression receives the column together with its full path
260+ * (as [ColumnWithPath]) and must return the new name for that column.
261+ * The operation preserves the original columns’ values and their positions within the [DataFrame].
262+ *
263+ * For more information: {@include [DocumentationUrls.Rename]}
264+ *
265+ * Check out [Grammar][RenameDocs.Grammar] for more details.
266+ *
267+ * ### Examples:
268+ * ```kotlin
269+ * // Rename all columns using their full path, delimited by "->"
270+ * df.rename { colsAtAnyDepth() }.into { it.path.joinToString("->") }
271+ *
272+ * // Rename all `String` columns with uppercase
273+ * df.rename { colsOf<String>() }.into { it.name.uppercase() }
274+ * ```
275+ *
276+ * @param transform A function that takes a [ColumnWithPath] for each selected column
277+ * and returns the new column name.
278+ * @return A new [DataFrame] with the columns renamed.
279+ */
201280public fun <T , C > RenameClause <T , C >.into (transform : (ColumnWithPath <C >) -> String ): DataFrame <T > =
202281 renameImpl(transform)
203282
204283/* *
205- * ## Rename to "camelCase"
206- *
207284 * Renames the columns, previously selected with [rename] to "camelCase" format.
285+ *
208286 * All delimiters between words are removed, words are capitalized except for the first one.
209287 * Places underscore between numbers.
210288 * If the string does not contain any letters or numbers, it remains unchanged.
@@ -214,7 +292,12 @@ public fun <T, C> RenameClause<T, C>.into(transform: (ColumnWithPath<C>) -> Stri
214292 * This function supports converting names from `snake_case`, `PascalCase`, and other delimited formats
215293 * into a consistent "camelCase" representation.
216294 *
217- * ### Examples:
295+ * ### Examples
296+ * ```kotlin
297+ * df.rename("arrival_date", "passport-ID").toCamelCase()
298+ * ```
299+ *
300+ * #### Renaming Examples
218301 * ```
219302 * "snake_case_name" -> "snakeCaseName"
220303 * "PascalCaseName" -> "pascalCaseName"
@@ -233,7 +316,6 @@ public fun <T, C> RenameClause<T, C>.toCamelCase(): DataFrame<T> = into { it.ren
233316// region DataColumn
234317
235318/* *
236- * ## Rename to camelCase
237319 *
238320 * Renames this column to "camelCase" format.
239321 * All delimiters between words are removed, words are capitalized except for the first one.
@@ -245,7 +327,7 @@ public fun <T, C> RenameClause<T, C>.toCamelCase(): DataFrame<T> = into { it.ren
245327 * This function supports converting names from `snake_case`, `PascalCase`, and other delimited formats
246328 * into a consistent "camelCase" representation.
247329 *
248- * ### Examples:
330+ * #### Renaming Examples
249331 * ```
250332 * "snake_case_name" -> "snakeCaseName"
251333 * "PascalCaseName" -> "pascalCaseName"
@@ -261,20 +343,44 @@ public fun <T, C : ColumnReference<T>> C.renameToCamelCase(): C =
261343 ) as C
262344
263345@Suppress(" UNCHECKED_CAST" )
346+ @AccessApiOverload
347+ @Deprecated(DEPRECATED_ACCESS_API )
264348public fun <T , C : ColumnReference <T >> C.rename (column : KProperty <T >): C = rename(column.columnName) as C
265349
266350@Suppress(" UNCHECKED_CAST" )
351+ @AccessApiOverload
352+ @Deprecated(DEPRECATED_ACCESS_API )
267353public fun <T , C : ColumnReference <T >> C.rename (column : ColumnAccessor <T >): C = rename(column.name()) as C
268354
269355// endregion
270356
271357// region named
272358
359+ /* *
360+ * Returns a new column reference with the original column values but a new [name].
361+ *
362+ * This is useful when you want to specify an existing column
363+ * (for example, in `select`, `update`, or `rename` operations)
364+ * but give it a different name in the resulting [DataFrame].
365+ *
366+ * ### Example:
367+ * ```kotlin
368+ * // Select "size" column as "dimensions"
369+ * df.select { size named "dimensions" }
370+ * ```
371+ *
372+ * @param name The new name to assign to the column.
373+ * @return A new column with the original structure and values but with the specified [name].
374+ */
273375@Suppress(" UNCHECKED_CAST" )
274376public infix fun <T , C : ColumnReference <T >> C.named (name : String ): C = rename(name) as C
275377
378+ @AccessApiOverload
379+ @Deprecated(DEPRECATED_ACCESS_API )
276380public infix fun <T , C : ColumnReference <T >> C.named (name : KProperty <* >): C = rename(name)
277381
382+ @AccessApiOverload
383+ @Deprecated(DEPRECATED_ACCESS_API )
278384public infix fun <T , C : ColumnReference <T >> C.named (name : ColumnAccessor <* >): C = rename(name)
279385
280386// endregion
0 commit comments