Skip to content

Commit aba878c

Browse files
Automated commit of generated code
1 parent 4b1f21e commit aba878c

12 files changed

Lines changed: 116 additions & 42 deletions

File tree

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

Lines changed: 81 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.jetbrains.kotlinx.dataframe.impl.columnName
2727
import org.jetbrains.kotlinx.dataframe.impl.columns.renamedColumn
2828
import org.jetbrains.kotlinx.dataframe.impl.toCamelCaseByDelimiters
2929
import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
30+
import org.jetbrains.kotlinx.dataframe.util.RENAME_INTO
3031
import kotlin.reflect.KProperty
3132

3233
// region DataFrame
@@ -38,8 +39,8 @@ import kotlin.reflect.KProperty
3839
* returns a [RenameClause],
3940
* which serves as an intermediate step.
4041
* The [RenameClause] object provides methods to rename selected columns using:
41-
* - [into(name)][RenameClause.into] - renames selected columns to the specified names.
42-
* - [into { nameExpression }][RenameClause.into] - renames selected columns using a provided
42+
* - [to(name)][RenameClause.to] - renames selected columns to the specified names.
43+
* - [to { nameExpression }][RenameClause.to] - renames selected columns using a provided
4344
* expression assuming column with its path and returning a new name.
4445
* - [toCamelCase()][RenameClause.toCamelCase] - renames all selected columns to "camelCase".
4546
*
@@ -127,10 +128,10 @@ internal interface RenameDocs {
127128
* [**`rename`**][rename]**` { `**`columnsSelector: `[`ColumnsSelector`][ColumnsSelector]` `**`}`**
128129
*
129130
*     
130-
* `| `__`.`__[**`into`**][RenameClause.into]**`(`**`name: `[`String`][String]**`)`**
131+
* `| `__`.`__[**`to`**][RenameClause.to]**`(`**`newNames: `[`String`][String]**`, ..)`**
131132
*
132133
*     
133-
* `| `__`.`__[**`into`**][RenameClause.into]**` { `**`nameExpression: (`[`ColumnWithPath`][ColumnWithPath]`) -> `[String]` `**`}`**
134+
* `| `__`.`__[**`to`**][RenameClause.to]**` { `**`nameExpression: (`[`ColumnWithPath`][ColumnWithPath]`) -> `[String]` `**`}`**
134135
*
135136
*     
136137
* `| `__`.`__[**`toCamelCase`**][RenameClause.toCamelCase]**`()`**
@@ -159,7 +160,7 @@ internal interface RenameDocs {
159160
@Interpretable("RenameMapping")
160161
public fun <T> DataFrame<T>.rename(vararg mappings: Pair<String, String>): DataFrame<T> =
161162
rename { mappings.map { it.first.toColumnAccessor() }.toColumnSet() }
162-
.into(*mappings.map { it.second }.toTypedArray())
163+
.to(*mappings.map { it.second }.toTypedArray())
163164

164165
/**
165166
* Renames the specified [columns] keeping their original values and location within the [DataFrame][org.jetbrains.kotlinx.dataframe.DataFrame].
@@ -168,8 +169,8 @@ public fun <T> DataFrame<T>.rename(vararg mappings: Pair<String, String>): DataF
168169
* returns a [RenameClause][org.jetbrains.kotlinx.dataframe.api.RenameClause],
169170
* which serves as an intermediate step.
170171
* The [RenameClause][org.jetbrains.kotlinx.dataframe.api.RenameClause] object provides methods to rename selected columns using:
171-
* - [into(name)][org.jetbrains.kotlinx.dataframe.api.RenameClause.into] - renames selected columns to the specified names.
172-
* - [into { nameExpression }][org.jetbrains.kotlinx.dataframe.api.RenameClause.into] - renames selected columns using a provided
172+
* - [to(name)][org.jetbrains.kotlinx.dataframe.api.RenameClause.to] - renames selected columns to the specified names.
173+
* - [to { nameExpression }][org.jetbrains.kotlinx.dataframe.api.RenameClause.to] - renames selected columns using a provided
173174
* expression assuming column with its path and returning a new name.
174175
* - [toCamelCase()][org.jetbrains.kotlinx.dataframe.api.RenameClause.toCamelCase] - renames all selected columns to "camelCase".
175176
*
@@ -205,10 +206,10 @@ public fun <T> DataFrame<T>.rename(vararg mappings: Pair<String, String>): DataF
205206
* ### Examples:
206207
* ```kotlin
207208
* // Rename "col1" to "width" and "col2" to "length"
208-
* df.rename { col1 and col2 }.into("width", "length")
209+
* df.rename { col1 and col2 }.to("width", "length")
209210
*
210211
* // Rename all columns using their full path, delimited by "->"
211-
* df.rename { colsAtAnyDepth() }.into { it.path.joinToString("->") }
212+
* df.rename { colsAtAnyDepth() }.to { it.path.joinToString("->") }
212213
*
213214
* // Renames all numeric columns to "camelCase"
214215
* df.rename { colsOf<Number>() }.toCamelCase()
@@ -234,8 +235,8 @@ public fun <T, C> DataFrame<T>.rename(vararg cols: KProperty<C>): RenameClause<T
234235
* returns a [RenameClause][org.jetbrains.kotlinx.dataframe.api.RenameClause],
235236
* which serves as an intermediate step.
236237
* The [RenameClause][org.jetbrains.kotlinx.dataframe.api.RenameClause] object provides methods to rename selected columns using:
237-
* - [into(name)][org.jetbrains.kotlinx.dataframe.api.RenameClause.into] - renames selected columns to the specified names.
238-
* - [into { nameExpression }][org.jetbrains.kotlinx.dataframe.api.RenameClause.into] - renames selected columns using a provided
238+
* - [to(name)][org.jetbrains.kotlinx.dataframe.api.RenameClause.to] - renames selected columns to the specified names.
239+
* - [to { nameExpression }][org.jetbrains.kotlinx.dataframe.api.RenameClause.to] - renames selected columns using a provided
239240
* expression assuming column with its path and returning a new name.
240241
* - [toCamelCase()][org.jetbrains.kotlinx.dataframe.api.RenameClause.toCamelCase] - renames all selected columns to "camelCase".
241242
*
@@ -260,7 +261,7 @@ public fun <T, C> DataFrame<T>.rename(vararg cols: KProperty<C>): RenameClause<T
260261
* ### Examples:
261262
* ```kotlin
262263
* // Rename "col1" to "width" and "col2" to "length"
263-
* df.rename("col1", "col2").into("width", "length")
264+
* df.rename("col1", "col2").to("width", "length")
264265
*
265266
* // Renames "arrival_date" and "passport-ID" columns to "camelCase"
266267
* df.rename("arrival_date", "passport-ID").toCamelCase()
@@ -281,8 +282,8 @@ public fun <T> DataFrame<T>.rename(vararg cols: String): RenameClause<T, Any?> =
281282
* in the [DataFrame], but their names will be changed.
282283
*
283284
* Use the following methods to perform the conversion:
284-
* - [into(name)][RenameClause.into] — renames selected columns to the specified names.
285-
* - [into { nameExpression }][RenameClause.into] — renames selected columns using a custom expression,
285+
* - [to(name)][RenameClause.to] — renames selected columns to the specified names.
286+
* - [to { nameExpression }][RenameClause.to] — renames selected columns using a custom expression,
286287
* which takes the column and its path and returns a new name.
287288
* - [toCamelCase()][RenameClause.toCamelCase] — renames all selected columns to `camelCase`.
288289
*
@@ -335,9 +336,12 @@ public fun <T> DataFrame<T>.renameToCamelCase(): DataFrame<T> =
335336
@Deprecated(DEPRECATED_ACCESS_API)
336337
@AccessApiOverload
337338
public fun <T, C> RenameClause<T, C>.into(vararg newColumns: ColumnReference<*>): DataFrame<T> =
338-
into(*newColumns.map { it.name() }.toTypedArray())
339+
to(*newColumns.map { it.name() }.toTypedArray())
339340

340341
/**
342+
* __NOTE:__ While you can keep using 'into', we recommend using [to][RenameClause.to] for
343+
* * better readability and more natural English.
344+
*
341345
* Renames the columns selected with [rename] to the specified [newNames],
342346
* preserving their values and positions within the [DataFrame].
343347
*
@@ -363,14 +367,46 @@ public fun <T, C> RenameClause<T, C>.into(vararg newColumns: ColumnReference<*>)
363367
*/
364368
@Refine
365369
@Interpretable("RenameInto")
370+
@Deprecated(message = RENAME_INTO, replaceWith = ReplaceWith("to(*newNames)"))
366371
public fun <T, C> RenameClause<T, C>.into(vararg newNames: String): DataFrame<T> = renameImpl(newNames)
367372

373+
/**
374+
* Renames the columns selected with [rename] to the specified [newNames],
375+
* preserving their values and positions within the [DataFrame].
376+
*
377+
* The mapping is positional: [newNames] are applied in the order
378+
* the columns were selected — the first selected column is renamed to the first name,
379+
* the second to the second, and so on.
380+
*
381+
* For more information: [See `rename` on the documentation website.](https://kotlin.github.io/dataframe/rename.html)
382+
*
383+
* Check out [Grammar][RenameDocs.Grammar].
384+
*
385+
* ### Examples:
386+
* ```kotlin
387+
* // Rename "col1" to "width" and "col2" to "length"
388+
* df.rename("col1", "col2").to("width", "length")
389+
*
390+
* // Rename "col1" to "width" and "col2" to "length"
391+
* df.rename { col1 and col2 }.to("width", "length")
392+
* ```
393+
*
394+
* @param newNames The new names for the selected columns, applied in order of selecting.
395+
* @return A new [DataFrame] with the columns renamed.
396+
*/
397+
@Refine
398+
@Interpretable("RenameInto")
399+
public fun <T, C> RenameClause<T, C>.to(vararg newNames: String): DataFrame<T> = renameImpl(newNames)
400+
368401
@Deprecated(DEPRECATED_ACCESS_API)
369402
@AccessApiOverload
370403
public fun <T, C> RenameClause<T, C>.into(vararg newNames: KProperty<*>): DataFrame<T> =
371-
into(*newNames.map { it.name }.toTypedArray())
404+
to(*newNames.map { it.name }.toTypedArray())
372405

373406
/**
407+
* __NOTE:__ While you can keep using 'into', we recommend using [to][RenameClause.to] for
408+
* better readability and more natural English.
409+
*
374410
* Renames the columns selected with [rename] by applying the [transform] expression
375411
* to each of them. This expression receives the column together with its full path
376412
* (as [ColumnWithPath]) and must return the new name for that column.
@@ -395,9 +431,37 @@ public fun <T, C> RenameClause<T, C>.into(vararg newNames: KProperty<*>): DataFr
395431
*/
396432
@Refine
397433
@Interpretable("RenameIntoLambda")
434+
@Deprecated(message = RENAME_INTO, replaceWith = ReplaceWith("to(transform)"))
398435
public fun <T, C> RenameClause<T, C>.into(transform: (ColumnWithPath<C>) -> String): DataFrame<T> =
399436
renameImpl(transform)
400437

438+
/**
439+
* Renames the columns selected with [rename] by applying the [transform] expression
440+
* to each of them. This expression receives the column together with its full path
441+
* (as [ColumnWithPath]) and must return the new name for that column.
442+
* The operation preserves the original columns’ values and their positions within the [DataFrame].
443+
*
444+
* For more information: [See `rename` on the documentation website.](https://kotlin.github.io/dataframe/rename.html)
445+
*
446+
* Check out [Grammar][RenameDocs.Grammar] for more details.
447+
*
448+
* ### Examples:
449+
* ```kotlin
450+
* // Rename all columns using their full path, delimited by "->"
451+
* df.rename { colsAtAnyDepth() }.to { it.path.joinToString("->") }
452+
*
453+
* // Rename all `String` columns with uppercase
454+
* df.rename { colsOf<String>() }.to { it.name.uppercase() }
455+
* ```
456+
*
457+
* @param transform A function that takes a [ColumnWithPath] for each selected column
458+
* and returns the new column name.
459+
* @return A new [DataFrame] with the columns renamed.
460+
*/
461+
@Refine
462+
@Interpretable("RenameIntoLambda")
463+
public fun <T, C> RenameClause<T, C>.to(transform: (ColumnWithPath<C>) -> String): DataFrame<T> = renameImpl(transform)
464+
401465
/**
402466
* Renames the columns, previously selected with [rename] to "camelCase" format.
403467
*
@@ -430,7 +494,7 @@ public fun <T, C> RenameClause<T, C>.into(transform: (ColumnWithPath<C>) -> Stri
430494
*/
431495
@Refine
432496
@Interpretable("RenameToCamelCaseClause")
433-
public fun <T, C> RenameClause<T, C>.toCamelCase(): DataFrame<T> = into { it.renameToCamelCase().name() }
497+
public fun <T, C> RenameClause<T, C>.toCamelCase(): DataFrame<T> = to { it.renameToCamelCase().name() }
434498

435499
// endregion
436500

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/GroupByImpl.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import org.jetbrains.kotlinx.dataframe.api.isColumnGroup
1818
import org.jetbrains.kotlinx.dataframe.api.pathOf
1919
import org.jetbrains.kotlinx.dataframe.api.remove
2020
import org.jetbrains.kotlinx.dataframe.api.rename
21+
import org.jetbrains.kotlinx.dataframe.api.to
2122
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
2223
import org.jetbrains.kotlinx.dataframe.impl.aggregation.AggregatableInternal
2324
import org.jetbrains.kotlinx.dataframe.impl.aggregation.GroupByReceiverImpl
@@ -63,7 +64,7 @@ internal class GroupByImpl<T, G>(
6364
if (groupedColumnName == null || groupedColumnName == groups.name()) {
6465
df
6566
} else {
66-
df.rename(groups).into(groupedColumnName)
67+
df.rename(groups).to(groupedColumnName)
6768
}
6869
}
6970

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/util/deprecationMessages.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,8 @@ internal const val ALL_COLS_EXCEPT_REPLACE = "this.allColsExcept { other }"
304304
internal const val ALL_COLS_EXCEPT_REPLACE_VARARG = "this.allColsExcept { others.toColumnSet() }"
305305
internal const val EXCEPT_REPLACE = "this.except { other }"
306306
internal const val EXCEPT_REPLACE_VARARG = "this.except { others.toColumnSet() }"
307+
308+
internal const val RENAME_INTO =
309+
"'into' has been replaced with 'to', because 'rename to' is more common in English. You can keep using 'into', but we advise using 'to'."
310+
307311
// endregion

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/allExcept.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class AllExceptTests : ColumnsSelectionDslTests() {
1818

1919
@Test
2020
fun `issue 761`() {
21-
val renamed = df.rename { colsAtAnyDepth() except name.firstName }.into { it.name.uppercase() }
21+
val renamed = df.rename { colsAtAnyDepth() except name.firstName }.to { it.name.uppercase() }
2222
renamed.columnNames() shouldBe listOf("NAME", "AGE", "CITY", "WEIGHT", "ISHAPPY")
2323
renamed.getColumnGroup("NAME").columnNames() shouldBe listOf("firstName", "LASTNAME")
2424

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/constructors.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ class ConstructorsTests {
304304

305305
else -> error("Unexpected column name: $it")
306306
}
307-
}.rename { all() }.into { names[it.name.toInt() - 1] }
307+
}.rename { all() }.to { names[it.name.toInt() - 1] }
308308

309309
val df4 = dataFrameOf(names).invoke {
310310
when (it) {

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/flatten.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.jetbrains.kotlinx.dataframe.api
33
import io.kotest.matchers.shouldBe
44
import org.jetbrains.kotlinx.dataframe.DataRow
55
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
6+
import org.jetbrains.kotlinx.dataframe.api.to
67
import org.junit.Test
78

89
@Suppress("ktlint:standard:argument-list-wrapping")
@@ -72,7 +73,7 @@ class FlattenTests {
7273
val grouped = df
7374
.group("a", "b").into("e")
7475
.group("e", "c").into("f")
75-
.rename { "f"["e"] }.into("a")
76+
.rename { "f"["e"] }.to("a")
7677
val flattened = grouped.flatten { "f"["a"] }
7778
flattened.getColumnGroup("f").columnNames() shouldBe listOf("a", "b", "c")
7879
flattened.ungroup("f") shouldBe df

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/format.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.kotest.matchers.shouldNotBe
55
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.blue
66
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.red
77
import org.jetbrains.kotlinx.dataframe.api.FormattingDsl.rgb
8+
import org.jetbrains.kotlinx.dataframe.api.to
89
import org.jetbrains.kotlinx.dataframe.io.DisplayConfiguration
910
import org.jetbrains.kotlinx.dataframe.samples.api.TestBase
1011
import org.jetbrains.kotlinx.dataframe.samples.api.age
@@ -329,7 +330,7 @@ class FormatTests : TestBase() {
329330
.groupBy("city").toDataFrame()
330331
.add("cityCopy") { "city"<String>() }
331332
.group("city").into("cityGroup")
332-
.rename("cityCopy").into("city")
333+
.rename("cityCopy").to("city")
333334

334335
val formatted = df.format("city").with { bold and italic and textColor(green) }
335336
val html = formatted.toHtml().toString()

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/rename.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.jetbrains.kotlinx.dataframe.api
33
import io.kotest.assertions.asClue
44
import io.kotest.assertions.throwables.shouldNotThrowAny
55
import io.kotest.matchers.shouldBe
6+
import org.jetbrains.kotlinx.dataframe.api.to
67
import org.jetbrains.kotlinx.dataframe.impl.columns.asAnyFrameColumn
78
import org.jetbrains.kotlinx.dataframe.samples.api.age
89
import org.junit.Test
@@ -27,8 +28,8 @@ class RenameTests : ColumnsSelectionDslTests() {
2728
4, 5, 6,
2829
)
2930

30-
simpleDf.rename { all() }.into { it.name + "_renamed" } shouldBe renamedDf
31-
simpleDf.rename { all() }.into("a_renamed", "b_renamed", "c_renamed") shouldBe renamedDf
31+
simpleDf.rename { all() }.to { it.name + "_renamed" } shouldBe renamedDf
32+
simpleDf.rename { all() }.to("a_renamed", "b_renamed", "c_renamed") shouldBe renamedDf
3233
}
3334

3435
@Test
@@ -54,7 +55,7 @@ class RenameTests : ColumnsSelectionDslTests() {
5455

5556
groupedDf
5657
.rename { "group" and "group"["a"] }
57-
.into { it.name + "_renamed" } shouldBe renamedDf
58+
.to { it.name + "_renamed" } shouldBe renamedDf
5859
}
5960

6061
@Test
@@ -66,7 +67,7 @@ class RenameTests : ColumnsSelectionDslTests() {
6667

6768
groupedDf
6869
.rename { colsAtAnyDepth() }
69-
.into { it.name + "_renamed" } shouldBe renamedDf
70+
.to { it.name + "_renamed" } shouldBe renamedDf
7071
}
7172

7273
@Test
@@ -80,7 +81,7 @@ class RenameTests : ColumnsSelectionDslTests() {
8081

8182
doubleGroupedDf
8283
.rename { colsAtAnyDepth() }
83-
.into { it.name + "_renamed" } shouldBe renamedDf
84+
.to { it.name + "_renamed" } shouldBe renamedDf
8485
}
8586

8687
interface Person2 {

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Join.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.jetbrains.kotlinx.dataframe.api.leftJoin
1616
import org.jetbrains.kotlinx.dataframe.api.rename
1717
import org.jetbrains.kotlinx.dataframe.api.rightJoin
1818
import org.jetbrains.kotlinx.dataframe.api.select
19+
import org.jetbrains.kotlinx.dataframe.api.to
1920
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
2021
import org.jetbrains.kotlinx.dataframe.explainer.TransformDataFrameExpressions
2122
import org.junit.Test
@@ -55,7 +56,7 @@ class Join : TestBase() {
5556
@Test
5657
@TransformDataFrameExpressions
5758
fun joinWithMatch_properties() {
58-
val other = other.rename { name }.into("fullName").cast<Right>()
59+
val other = other.rename { name }.to("fullName").cast<Right>()
5960
val joined =
6061
// SampleStart
6162
df.join(other) { name match right.fullName }

0 commit comments

Comments
 (0)