File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
main/kotlin/org/jetbrains/kotlinx/dataframe/api
test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,18 @@ public interface ColumnSelectionDsl<out T> : ColumnsContainer<T> {
51
51
52
52
public operator fun <C > ColumnPath.invoke (): DataColumn <C > = getColumn(this ).cast()
53
53
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
+
54
66
public operator fun <C > String.invoke (): DataColumn <C > = getColumn(this ).cast()
55
67
56
68
public operator fun String.get (column : String ): ColumnPath = pathOf(this , column)
Original file line number Diff line number Diff line change @@ -706,6 +706,39 @@ class Access : TestBase() {
706
706
// SampleEnd
707
707
}
708
708
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
+
709
742
@Test
710
743
fun columnSelectors_strings () {
711
744
// SampleStart
You can’t perform that action at this time.
0 commit comments