Skip to content

Commit 796f74d

Browse files
committed
small and changes simplifying scopes. WIP kdocs for except
1 parent 8c81454 commit 796f74d

File tree

10 files changed

+259
-171
lines changed

10 files changed

+259
-171
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import org.jetbrains.kotlinx.dataframe.ColumnsSelector
44
import org.jetbrains.kotlinx.dataframe.DataColumn
55
import org.jetbrains.kotlinx.dataframe.DataFrame
66
import org.jetbrains.kotlinx.dataframe.DataRow
7-
import org.jetbrains.kotlinx.dataframe.api.AllExceptColumnsSelectionDsl.Usage.ColumnGroupName
87
import org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.Usage
98
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
109
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
@@ -112,7 +111,7 @@ public interface ColumnsSelectionDsl<out T> : /* SingleColumn<DataRow<T>> */
112111
// select {}, TODO due to String.invoke conflict this cannot be moved out of ColumnsSelectionDsl
113112
SelectColumnsSelectionDsl,
114113
// except(), allExcept {}, allColsExcept {}
115-
AllExceptColumnsSelectionDsl<T>,
114+
AllExceptColumnsSelectionDsl,
116115

117116
// nameContains(""), childrenNameContains(""), nameStartsWith(""), childrenNameEndsWith("")
118117
ColumnNameFiltersColumnsSelectionDsl,
@@ -520,7 +519,7 @@ public interface ColumnsSelectionDsl<out T> : /* SingleColumn<DataRow<T>> */
520519
* Invokes the given [ColumnsSelector] using this [ColumnsSelectionDsl].
521520
*/
522521
public operator fun <C> ColumnsSelector<T, C>.invoke(): ColumnsResolver<C> =
523-
this(this@ColumnsSelectionDsl, this@ColumnsSelectionDsl)
522+
this@invoke(this@ColumnsSelectionDsl, this@ColumnsSelectionDsl)
524523

525524
/**
526525
* ## Deprecated: Columns by Index Range from List of Columns

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

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package org.jetbrains.kotlinx.dataframe.api
22

33
import org.jetbrains.kotlinx.dataframe.ColumnsSelector
4+
import org.jetbrains.kotlinx.dataframe.DataColumn
5+
import org.jetbrains.kotlinx.dataframe.DataFrame
46
import org.jetbrains.kotlinx.dataframe.DataRow
7+
import org.jetbrains.kotlinx.dataframe.api.AllExceptColumnsSelectionDsl.Usage.ColumnGroupName
8+
import org.jetbrains.kotlinx.dataframe.api.AllExceptColumnsSelectionDsl.Usage.ColumnSetName
59
import org.jetbrains.kotlinx.dataframe.api.AllExceptColumnsSelectionDsl.Usage.PlainDslName
10+
import org.jetbrains.kotlinx.dataframe.columns.ColumnGroup
611
import org.jetbrains.kotlinx.dataframe.columns.ColumnPath
712
import org.jetbrains.kotlinx.dataframe.columns.ColumnSet
813
import org.jetbrains.kotlinx.dataframe.columns.ColumnsResolver
@@ -29,7 +34,7 @@ import kotlin.reflect.KProperty
2934

3035
// region ColumnsSelectionDsl
3136

32-
public interface AllExceptColumnsSelectionDsl<out T> {
37+
public interface AllExceptColumnsSelectionDsl {
3338

3439
/**
3540
* ## (All) (Cols) Except Usage
@@ -128,8 +133,124 @@ public interface AllExceptColumnsSelectionDsl<out T> {
128133
public interface ColumnGroupName
129134
}
130135

136+
/**
137+
* ## (All) (Cols) Except
138+
*
139+
* Exclude the given columns from the current selection.
140+
*
141+
* ### On [ColumnSets][ColumnSet]
142+
* This function can be explained the easiest on [ColumnSets][ColumnSet]. Let's say we want all
143+
* integer columns apart from `age` and `height`.
144+
*
145+
* We can do:
146+
*
147+
* `df.`[select][DataFrame.select]` { `[colsOf][colsOf]`<`[Int][Int]`>() `[except][ColumnSet.except]` { age `[and][ColumnsSelectionDsl.and]` height } }`
148+
*
149+
* Which will remove the [ColumnSet] created by `age `[and][ColumnsSelectionDsl.and]` height` from the [ColumnSet] created by [colsOf][colsOf]`<`[Int][Int]`>()`.
150+
*
151+
* &nbsp;&nbsp;&nbsp;&nbsp;
152+
*
153+
* This operation can also be done with columns that are from inside a [ColumnGroup].
154+
*
155+
* For instance:
156+
*
157+
* `df.`[select][DataFrame.select]` { `[colsAtAnyDepth][ColumnsSelectionDsl.colsAtAnyDepth]` { "a" `[in][String.contains]` it.`[name][DataColumn.name]`() } `[except][ColumnSet.except]` userData.age }`
158+
*
159+
* &nbsp;&nbsp;&nbsp;&nbsp;
160+
*
161+
* NOTE: If a column that needs to be removed appears multiple times, it is excepted
162+
* each time it is encountered (including inside [ColumnGroups][ColumnGroup]). You could say the receiver [ColumnSet]
163+
* is [simplified][ColumnsSelectionDsl.simplify] before the operation is performed:
164+
*
165+
* `(`[cols][ColumnsSelectionDsl.cols]`(userData, userData, userData.age, userData.age) `[except][ColumnSet.except]` userData.age) == (`[cols][ColumnsSelectionDsl.cols]`(userData) `[except][ColumnSet.except]` userData.age)`
166+
*
167+
* ### In the [ColumnsSelectionDsl][ColumnsSelectionDsl]
168+
* Instead of having to write [all][ColumnsSelectionDsl.all]`() `[except][ColumnsSelectionDsl.except]` { ... }` in the DSL,
169+
* you can use [allExcept][ColumnsSelectionDsl.allExcept]` { ... }` to achieve the same result.
170+
*
171+
* For example:
172+
*
173+
* `df.`[select][DataFrame.select]` { `[allExcept][ColumnsSelectionDsl.allExcept]` { userData.age `[and][ColumnsSelectionDsl.and]` height } }`
174+
*
175+
* ### On [ColumnGroups][ColumnGroup]
176+
* The variant of this function on [ColumnGroups][ColumnGroup] is a bit different as it operates on the columns
177+
* inside the group instead of in the DSL-scope. In other words, `myColGroup.`[allColsExcept][SingleColumn.allColsExcept]` { col } ` is
178+
* a shortcut for `myColGroup.`[select][ColumnsSelectionDsl.select]` { `[all][ColumnsSelectionDsl.all]`() `[except][ColumnSet]` col }`.
179+
*
180+
* Also note the name change, similar to [allCols][ColumnsSelectionDsl.allCols], this makes it clearer that your operating
181+
* on the columns in the group.
182+
*
183+
* ### Examples for this overload
184+
* {@getArg [ExampleArg]}
185+
*
186+
* {@getArg [ParamArg]}
187+
* @return A [ColumnSet] containing all columns in [this\] except the specified ones.
188+
*/
189+
private interface CommonExceptDocs {
190+
191+
/* Example argument */
192+
interface ExampleArg
193+
194+
/* Parameter argument */
195+
interface ParamArg
196+
}
197+
131198
// region ColumnSet
132199

200+
/**
201+
* ## (All) (Cols) Except
202+
*
203+
* Exclude the given columns from the current selection.
204+
*
205+
* ### On [ColumnSets][org.jetbrains.kotlinx.dataframe.columns.ColumnSet]
206+
* This function can be explained the easiest on [ColumnSets][org.jetbrains.kotlinx.dataframe.columns.ColumnSet]. Let's say we want all
207+
* integer columns apart from `age` and `height`.
208+
*
209+
* We can do:
210+
*
211+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `[colsOf][org.jetbrains.kotlinx.dataframe.api.colsOf]`<`[Int][Int]`>() `[except][org.jetbrains.kotlinx.dataframe.columns.ColumnSet.except]` { age `[and][org.jetbrains.kotlinx.dataframe.api.AndColumnsSelectionDsl.and]` height } }`
212+
*
213+
* Which will remove the [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] created by `age `[and][org.jetbrains.kotlinx.dataframe.api.AndColumnsSelectionDsl.and]` height` from the [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] created by [colsOf][org.jetbrains.kotlinx.dataframe.api.colsOf]`<`[Int][Int]`>()`.
214+
*
215+
* &nbsp;&nbsp;&nbsp;&nbsp;
216+
*
217+
* This operation can also be done with columns that are from inside a [ColumnGroup][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup].
218+
*
219+
* For instance:
220+
*
221+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `[colsAtAnyDepth][org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.colsAtAnyDepth]` { "a" `[in][String.contains]` it.`[name][org.jetbrains.kotlinx.dataframe.DataColumn.name]`() } `[except][org.jetbrains.kotlinx.dataframe.columns.ColumnSet.except]` userData.age }`
222+
*
223+
* &nbsp;&nbsp;&nbsp;&nbsp;
224+
*
225+
* NOTE: If a column that needs to be removed appears multiple times, it is excepted
226+
* each time it is encountered (including inside [ColumnGroups][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup]). You could say the receiver [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet]
227+
* is [simplified][org.jetbrains.kotlinx.dataframe.api.SimplifyColumnsSelectionDsl.simplify] before the operation is performed:
228+
*
229+
* `(`[cols][org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.cols]`(userData, userData, userData.age, userData.age) `[except][org.jetbrains.kotlinx.dataframe.columns.ColumnSet.except]` userData.age) == (`[cols][org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.cols]`(userData) `[except][org.jetbrains.kotlinx.dataframe.columns.ColumnSet.except]` userData.age)`
230+
*
231+
* ### In the [ColumnsSelectionDsl][org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl]
232+
* Instead of having to write [all][org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.all]`() `[except][org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.except]` { ... }` in the DSL,
233+
* you can use [allExcept][org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.allExcept]` { ... }` to achieve the same result.
234+
*
235+
* For example:
236+
*
237+
* `df.`[select][org.jetbrains.kotlinx.dataframe.DataFrame.select]` { `[allExcept][org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.allExcept]` { userData.age `[and][org.jetbrains.kotlinx.dataframe.api.AndColumnsSelectionDsl.and]` height } }`
238+
*
239+
* ### On [ColumnGroups][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup]
240+
* The variant of this function on [ColumnGroups][org.jetbrains.kotlinx.dataframe.columns.ColumnGroup] is a bit different as it operates on the columns
241+
* inside the group instead of in the DSL-scope. In other words, `myColGroup.`[allColsExcept][org.jetbrains.kotlinx.dataframe.columns.SingleColumn.allColsExcept]` { col } ` is
242+
* a shortcut for `myColGroup.`[select][org.jetbrains.kotlinx.dataframe.api.SelectColumnsSelectionDsl.select]` { `[all][org.jetbrains.kotlinx.dataframe.api.ColumnsSelectionDsl.all]`() `[except][org.jetbrains.kotlinx.dataframe.columns.ColumnSet]` col }`.
243+
*
244+
* Also note the name change, similar to [allCols][org.jetbrains.kotlinx.dataframe.api.AllColumnsSelectionDsl.allCols], this makes it clearer that your operating
245+
* on the columns in the group.
246+
*
247+
* ### Examples for this overload
248+
* TODO
249+
*
250+
* @param [selector] A lambda in which you specify the columns that need to be
251+
* excluded from the [ColumnSet]. The scope of the selector is the same as the outer scope.
252+
* @return A [ColumnSet][org.jetbrains.kotlinx.dataframe.columns.ColumnSet] containing all columns in [this] except the specified ones.
253+
*/
133254
public infix fun <C> ColumnSet<C>.except(selector: () -> ColumnsResolver<*>): ColumnSet<C> =
134255
except(selector())
135256

0 commit comments

Comments
 (0)