Skip to content

Commit 7be69da

Browse files
committed
Merge branch 'master' into gradle-conventions-init
2 parents b6d2204 + 4f4bf58 commit 7be69da

File tree

44 files changed

+1928
-34
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1928
-34
lines changed

core/api/core.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3900,6 +3900,7 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/api/RenameColumn
39003900
public fun into (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;Ljava/lang/String;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;
39013901
public fun into (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;Lkotlin/reflect/KProperty;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;
39023902
public fun into (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;
3903+
public fun into (Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;Ljava/lang/String;)Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;
39033904
public fun named (Ljava/lang/String;Ljava/lang/String;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;
39043905
public fun named (Ljava/lang/String;Lkotlin/reflect/KProperty;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;
39053906
public fun named (Ljava/lang/String;Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;
@@ -3909,6 +3910,7 @@ public abstract interface class org/jetbrains/kotlinx/dataframe/api/RenameColumn
39093910
public fun named (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;Ljava/lang/String;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;
39103911
public fun named (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;Lkotlin/reflect/KProperty;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;
39113912
public fun named (Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;)Lorg/jetbrains/kotlinx/dataframe/columns/ColumnReference;
3913+
public fun named (Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;Ljava/lang/String;)Lorg/jetbrains/kotlinx/dataframe/columns/SingleColumn;
39123914
}
39133915

39143916
public abstract interface class org/jetbrains/kotlinx/dataframe/api/RenameColumnsSelectionDsl$Grammar {

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/aggregation/ColumnsForAggregateSelectionDsl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public interface ColumnsForAggregateSelectionDsl<out T> : ColumnsSelectionDsl<T>
2020
public infix fun <C> ColumnSet<C>.into(name: String): ColumnSet<C> =
2121
ConfiguredAggregateColumn.withPath(this, pathOf(name))
2222

23-
public infix fun <C> SingleColumn<C>.into(name: String): SingleColumn<C> =
24-
ConfiguredAggregateColumn.withPath(this, pathOf(name))
23+
override infix fun <C> SingleColumn<C>.into(newName: String): SingleColumn<C> =
24+
ConfiguredAggregateColumn.withPath(this, pathOf(newName))
2525

2626
public infix fun <C> ColumnSet<C>.into(path: ColumnPath): ColumnSet<C> =
2727
ConfiguredAggregateColumn.withPath(this, path)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ public interface ColColumnsSelectionDsl<out _UNUSED> {
678678
*/
679679
@Suppress("INAPPLICABLE_JVM_NAME")
680680
@JvmName("colUnTyped")
681-
@Interpretable("Col")
681+
@Interpretable("ColByStringUntyped")
682682
public fun col(name: String): ColumnAccessor<*> = column<Any?>(name)
683683

684684
/**
@@ -731,7 +731,7 @@ public interface ColColumnsSelectionDsl<out _UNUSED> {
731731
* @param [name] The name of the column.
732732
* @param [C] The type of the column.
733733
*/
734-
@Interpretable("ColUntyped")
734+
@Interpretable("ColByString")
735735
public fun <C> col(name: String): ColumnAccessor<C> = column(name)
736736

737737
/**
@@ -2564,6 +2564,7 @@ public interface ColColumnsSelectionDsl<out _UNUSED> {
25642564
*/
25652565
@Suppress("INAPPLICABLE_JVM_NAME")
25662566
@JvmName("colUnTyped")
2567+
@Interpretable("ColByIndexUntyped")
25672568
public fun ColumnsSelectionDsl<*>.col(index: Int): SingleColumn<*> = col<Any?>(index)
25682569

25692570
/**
@@ -2617,6 +2618,7 @@ public interface ColColumnsSelectionDsl<out _UNUSED> {
26172618
* @throws [IndexOutOfBoundsException] if the index is out of bounds.
26182619
* @param [C] The type of the column.
26192620
*/
2621+
@Interpretable("ColByIndex")
26202622
public fun <C> ColumnsSelectionDsl<*>.col(index: Int): SingleColumn<C> = asSingleColumn().col<C>(index)
26212623

26222624
/**

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
1111
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
1212
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
1313
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
14+
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
1415
import org.jetbrains.kotlinx.dataframe.columns.renamedReference
1516
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
1617
import org.jetbrains.kotlinx.dataframe.documentation.AccessApiLink
@@ -23,6 +24,7 @@ import org.jetbrains.kotlinx.dataframe.documentation.LineBreak
2324
import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
2425
import org.jetbrains.kotlinx.dataframe.impl.api.renameImpl
2526
import org.jetbrains.kotlinx.dataframe.impl.columnName
27+
import org.jetbrains.kotlinx.dataframe.impl.columns.renamedColumn
2628
import org.jetbrains.kotlinx.dataframe.impl.toCamelCaseByDelimiters
2729
import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
2830
import kotlin.reflect.KProperty
@@ -641,6 +643,10 @@ public interface RenameColumnsSelectionDsl {
641643
*/
642644
interface KPropertyReceiver
643645

646+
/**
647+
*/
648+
interface SingleColumnReceiver
649+
644650
/**
645651
*/
646652
interface ColumnReferenceParam
@@ -922,6 +928,34 @@ public interface RenameColumnsSelectionDsl {
922928
public infix fun <C> KProperty<C>.named(nameOf: KProperty<*>): ColumnReference<C> =
923929
toColumnAccessor().named(nameOf.columnName)
924930

931+
/**
932+
* ## Rename: `named` / `into`
933+
* Renaming a column in the [ColumnsSelectionDsl][org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl] is done by calling the `infix` functions
934+
* [named][org.jetbrains.kotlinx.dataframe.columns.ColumnReference.named] or [into][org.jetbrains.kotlinx.dataframe.columns.ColumnReference.into]. They behave exactly the same,
935+
* so it's up to contextual preference which one to use. Any combination of [Access API][org.jetbrains.kotlinx.dataframe.documentation.AccessApi] can be
936+
* used to specify the column to rename and which name should be used instead.
937+
*
938+
* ### Check out: [Grammar][org.jetbrains.kotlinx.dataframe.api.RenameColumnsSelectionDsl.Grammar]
939+
*
940+
* #### For Example:
941+
*
942+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { name `[named][org.jetbrains.kotlinx.dataframe.columns.ColumnReference.named]` "Full Name" }`
943+
*
944+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `[expr][org.jetbrains.kotlinx.dataframe.api.expr]` { 0 } `[into][org.jetbrains.kotlinx.dataframe.columns.ColumnReference.into]` "zeroes" }`
945+
*
946+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { "colA" `[named][kotlin.String.named]` Type::colB }`
947+
*
948+
* #### Example for this overload:
949+
*
950+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { col(0) `[named][SingleColumn.named]` "columnB" }`
951+
*
952+
* @receiver The [SingleColumn] referencing the column to rename.
953+
* @param [newName] A [String] used to specify the new name of the column.
954+
* @return A [ColumnReference][org.jetbrains.kotlinx.dataframe.columns.ColumnReference] to the renamed column.
955+
*/
956+
@Interpretable("Named1")
957+
public infix fun <C> SingleColumn<C>.named(newName: String): SingleColumn<C> = renamedColumn(newName)
958+
925959
// endregion
926960

927961
// region into
@@ -1184,6 +1218,34 @@ public interface RenameColumnsSelectionDsl {
11841218
@AccessApiOverload
11851219
public infix fun <C> KProperty<C>.into(nameOf: KProperty<*>): ColumnReference<C> = named(nameOf)
11861220

1221+
/**
1222+
* ## Rename: `named` / `into`
1223+
* Renaming a column in the [ColumnsSelectionDsl][org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl] is done by calling the `infix` functions
1224+
* [named][org.jetbrains.kotlinx.dataframe.columns.ColumnReference.named] or [into][org.jetbrains.kotlinx.dataframe.columns.ColumnReference.into]. They behave exactly the same,
1225+
* so it's up to contextual preference which one to use. Any combination of [Access API][org.jetbrains.kotlinx.dataframe.documentation.AccessApi] can be
1226+
* used to specify the column to rename and which name should be used instead.
1227+
*
1228+
* ### Check out: [Grammar][org.jetbrains.kotlinx.dataframe.api.RenameColumnsSelectionDsl.Grammar]
1229+
*
1230+
* #### For Example:
1231+
*
1232+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { name `[named][org.jetbrains.kotlinx.dataframe.columns.ColumnReference.named]` "Full Name" }`
1233+
*
1234+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `[expr][org.jetbrains.kotlinx.dataframe.api.expr]` { 0 } `[into][org.jetbrains.kotlinx.dataframe.columns.ColumnReference.into]` "zeroes" }`
1235+
*
1236+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { "colA" `[named][kotlin.String.named]` Type::colB }`
1237+
*
1238+
* #### Example for this overload:
1239+
*
1240+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { col(0) `[into][SingleColumn.into]` "columnB" }`
1241+
*
1242+
* @receiver The [SingleColumn] referencing the column to rename.
1243+
* @param [newName] A [String] used to specify the new name of the column.
1244+
* @return A [ColumnReference][org.jetbrains.kotlinx.dataframe.columns.ColumnReference] to the renamed column.
1245+
*/
1246+
@Interpretable("Named1")
1247+
public infix fun <C> SingleColumn<C>.into(newName: String): SingleColumn<C> = named(newName)
1248+
11871249
// endregion
11881250
}
11891251

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.jetbrains.kotlinx.dataframe.impl.columns
2+
3+
import org.jetbrains.kotlinx.dataframe.columns.ColumnResolutionContext
4+
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
5+
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
6+
7+
internal class RenamedSingleColumn<C>(val source: SingleColumn<C>, val name: String) : SingleColumn<C> {
8+
9+
override fun resolveSingle(context: ColumnResolutionContext): ColumnWithPath<C>? =
10+
source.resolveSingle(context)?.let {
11+
it.data.rename(name).addPath(it.path)
12+
}
13+
}
14+
15+
internal fun <C> SingleColumn<C>.renamedColumn(newName: String): SingleColumn<C> = RenamedSingleColumn(this, newName)

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/common.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.jetbrains.kotlinx.dataframe.io
22

3+
import org.apache.commons.io.ByteOrderMark
34
import org.apache.commons.io.input.BOMInputStream
45
import org.jetbrains.kotlinx.dataframe.AnyFrame
56
import org.jetbrains.kotlinx.dataframe.DataFrame
@@ -88,5 +89,12 @@ public fun asUrl(fileOrUrl: String): URL =
8889
public fun InputStream.skippingBomCharacters(): InputStream =
8990
BOMInputStream.builder()
9091
.setInputStream(this)
92+
.setByteOrderMarks(
93+
ByteOrderMark.UTF_8,
94+
ByteOrderMark.UTF_16LE,
95+
ByteOrderMark.UTF_16BE,
96+
ByteOrderMark.UTF_32LE,
97+
ByteOrderMark.UTF_32BE,
98+
)
9199
.setInclude(false)
92100
.get()

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,40 @@ class RenameTests : ColumnsSelectionDslTests() {
156156
df.select { col("age") into col("age2") },
157157
).shouldAllBeEqual()
158158
}
159+
160+
@Test
161+
fun `col by index named`() {
162+
val df = dataFrameOf(
163+
"col0" to columnOf(1, 4),
164+
"col1" to columnOf(2, 5),
165+
"col2" to columnOf(3, 6),
166+
)
167+
168+
listOf(
169+
df.select { col(0) and (col(1) named "renamed") and col(2) },
170+
df.select { col(0) and (col(1) into "renamed") and col(2) },
171+
df.select { col(0) and (col<Int>(1) named "renamed") and col(2) },
172+
df.select { col(0) and (col<Int>(1) into "renamed") and col(2) },
173+
).shouldAllBeEqual()
174+
175+
val result = df.select { col(0) and (col(1) named "renamed") and col(2) }
176+
result.columnNames() shouldBe listOf("col0", "renamed", "col2")
177+
result["renamed"].toList() shouldBe listOf(2, 5)
178+
}
179+
180+
@Test
181+
fun `col by index named with convert`() {
182+
val df = dataFrameOf(
183+
"a" to columnOf(1, 4),
184+
"b" to columnOf(2, 5),
185+
"c" to columnOf(3, 6),
186+
)
187+
188+
val result = df.convert { col<Int>(0) named "newA" }.with { it * 10 }
189+
190+
result.columnNames() shouldBe listOf("newA", "b", "c")
191+
result["newA"].toList() shouldBe listOf(10, 40)
192+
}
159193
}
160194

161195
class RenameToCamelCaseTests {

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/aggregation/ColumnsForAggregateSelectionDsl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public interface ColumnsForAggregateSelectionDsl<out T> : ColumnsSelectionDsl<T>
2020
public infix fun <C> ColumnSet<C>.into(name: String): ColumnSet<C> =
2121
ConfiguredAggregateColumn.withPath(this, pathOf(name))
2222

23-
public infix fun <C> SingleColumn<C>.into(name: String): SingleColumn<C> =
24-
ConfiguredAggregateColumn.withPath(this, pathOf(name))
23+
override infix fun <C> SingleColumn<C>.into(newName: String): SingleColumn<C> =
24+
ConfiguredAggregateColumn.withPath(this, pathOf(newName))
2525

2626
public infix fun <C> ColumnSet<C>.into(path: ColumnPath): ColumnSet<C> =
2727
ConfiguredAggregateColumn.withPath(this, path)

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,14 @@ public interface ColColumnsSelectionDsl<out _UNUSED> {
226226
*/
227227
@Suppress("INAPPLICABLE_JVM_NAME")
228228
@JvmName("colUnTyped")
229-
@Interpretable("Col")
229+
@Interpretable("ColByStringUntyped")
230230
public fun col(name: String): ColumnAccessor<*> = column<Any?>(name)
231231

232232
/**
233233
* @include [ColNameDocs] {@set [CommonColDocs.RECEIVER]}
234234
* @include [CommonColDocs.ColumnTypeParam]
235235
*/
236-
@Interpretable("ColUntyped")
236+
@Interpretable("ColByString")
237237
public fun <C> col(name: String): ColumnAccessor<C> = column(name)
238238

239239
/**
@@ -524,12 +524,14 @@ public interface ColColumnsSelectionDsl<out _UNUSED> {
524524
*/
525525
@Suppress("INAPPLICABLE_JVM_NAME")
526526
@JvmName("colUnTyped")
527+
@Interpretable("ColByIndexUntyped")
527528
public fun ColumnsSelectionDsl<*>.col(index: Int): SingleColumn<*> = col<Any?>(index)
528529

529530
/**
530531
* @include [ColIndexDocs] {@set [CommonColDocs.RECEIVER]}
531532
* @include [CommonColDocs.ColumnTypeParam]
532533
*/
534+
@Interpretable("ColByIndex")
533535
public fun <C> ColumnsSelectionDsl<*>.col(index: Int): SingleColumn<C> = asSingleColumn().col<C>(index)
534536

535537
/**

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import org.jetbrains.kotlinx.dataframe.columns.ColumnAccessor
1111
import org.jetbrains.kotlinx.dataframe.columns.ColumnReference
1212
import org.jetbrains.kotlinx.dataframe.columns.ColumnWithPath
1313
import org.jetbrains.kotlinx.dataframe.columns.FrameColumn
14+
import org.jetbrains.kotlinx.dataframe.columns.SingleColumn
1415
import org.jetbrains.kotlinx.dataframe.columns.renamedReference
1516
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
1617
import org.jetbrains.kotlinx.dataframe.documentation.AccessApiLink
@@ -23,6 +24,7 @@ import org.jetbrains.kotlinx.dataframe.documentation.LineBreak
2324
import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns
2425
import org.jetbrains.kotlinx.dataframe.impl.api.renameImpl
2526
import org.jetbrains.kotlinx.dataframe.impl.columnName
27+
import org.jetbrains.kotlinx.dataframe.impl.columns.renamedColumn
2628
import org.jetbrains.kotlinx.dataframe.impl.toCamelCaseByDelimiters
2729
import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API
2830
import kotlin.reflect.KProperty
@@ -498,6 +500,12 @@ public interface RenameColumnsSelectionDsl {
498500
*/
499501
interface KPropertyReceiver
500502

503+
/**
504+
* @set [RECEIVER] col(0)
505+
* @set [RECEIVER_TYPE] SingleColumn
506+
*/
507+
interface SingleColumnReceiver
508+
501509
/**
502510
* @set [PARAM] columnB
503511
* @set [PARAM_NAME] nameOf
@@ -619,6 +627,15 @@ public interface RenameColumnsSelectionDsl {
619627
public infix fun <C> KProperty<C>.named(nameOf: KProperty<*>): ColumnReference<C> =
620628
toColumnAccessor().named(nameOf.columnName)
621629

630+
/**
631+
* @include [CommonRenameDocs]
632+
* @include [CommonRenameDocs.NamedFunctionName]
633+
* @include [CommonRenameDocs.SingleColumnReceiver]
634+
* @include [CommonRenameDocs.StringParam]
635+
*/
636+
@Interpretable("Named1")
637+
public infix fun <C> SingleColumn<C>.named(newName: String): SingleColumn<C> = renamedColumn(newName)
638+
622639
// endregion
623640

624641
// region into
@@ -710,6 +727,15 @@ public interface RenameColumnsSelectionDsl {
710727
@AccessApiOverload
711728
public infix fun <C> KProperty<C>.into(nameOf: KProperty<*>): ColumnReference<C> = named(nameOf)
712729

730+
/**
731+
* @include [CommonRenameDocs]
732+
* @include [CommonRenameDocs.IntoFunctionName]
733+
* @include [CommonRenameDocs.SingleColumnReceiver]
734+
* @include [CommonRenameDocs.StringParam]
735+
*/
736+
@Interpretable("Named1")
737+
public infix fun <C> SingleColumn<C>.into(newName: String): SingleColumn<C> = named(newName)
738+
713739
// endregion
714740
}
715741

0 commit comments

Comments
 (0)