Skip to content

Commit 31fa89a

Browse files
committed
wip
1 parent 62ab8a3 commit 31fa89a

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ public interface ColumnSelectionDsl<out T> : ColumnsContainer<T> {
5151

5252
public operator fun <C> ColumnPath.invoke(): DataColumn<C> = getColumn(this).cast()
5353

54+
public operator fun <T> KProperty<T>.invoke(): DataColumn<T> = this@ColumnSelectionDsl[this]
55+
56+
public operator fun <T> KProperty<DataRow<T>>.invoke(): ColumnGroup<T> = this@ColumnSelectionDsl[this]
57+
58+
public operator fun <T> KProperty<DataFrame<T>>.invoke(): FrameColumn<T> = this@ColumnSelectionDsl[this]
59+
60+
public operator fun <T, R> KProperty<DataRow<T>>.get(column: KProperty<R>): DataColumn<R> = invoke()[column]
61+
62+
public operator fun <T, R> KProperty<DataRow<T>>.get(column: KProperty<DataRow<R>>): ColumnGroup<R> = invoke()[column]
63+
64+
public operator fun <T, R> KProperty<DataRow<T>>.get(column: KProperty<DataFrame<R>>): FrameColumn<R> = invoke()[column]
65+
5466
public operator fun <C> String.invoke(): DataColumn<C> = getColumn(this).cast()
5567

5668
public operator fun String.get(column: String): ColumnPath = pathOf(this, column)

core/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Access.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,39 @@ class Access : TestBase() {
706706
// SampleEnd
707707
}
708708

709+
@Test
710+
fun columnSelectors_kProperties() {
711+
// SampleStart
712+
df.select { it[Person::name] }
713+
df.select { (Person::name)() }
714+
715+
// by column path
716+
df.select { it[Person::name][Name::firstName] }
717+
df.select { Person::name[Name::firstName] }
718+
719+
// with a new name
720+
df.select { Person::name named "Full Name" }
721+
722+
// converted
723+
df.select { Person::name[Name::firstName].map { it.lowercase() } }
724+
725+
// column arithmetics
726+
df.select { 2021 - Person::age }
727+
728+
// two columns
729+
df.select { Person::name and Person::age }
730+
731+
// range of columns
732+
df.select { Person::name..Person::age }
733+
734+
// all children of ColumnGroup
735+
df.select { Person::name.all() }
736+
737+
// dfs traversal of all children columns
738+
df.select { Person::name.allDfs() }
739+
// SampleEnd
740+
}
741+
709742
@Test
710743
fun columnSelectors_strings() {
711744
// SampleStart

0 commit comments

Comments
 (0)