-
Notifications
You must be signed in to change notification settings - Fork 75
Move to(Start) keeping inside group #1489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
CarloMariaProietti
wants to merge
30
commits into
Kotlin:master
Choose a base branch
from
CarloMariaProietti:move_to_inside_group
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
8f73fb8
test is not working
CarloMariaProietti b581a92
average case is working but only that
CarloMariaProietti cebda41
ready to fix case when columnIndex==colPosition
CarloMariaProietti ccf9ba2
each test works
CarloMariaProietti e5137ae
improving tests
CarloMariaProietti 6fc8e98
each test works
CarloMariaProietti cbf53e7
cleaning + logic improvement
CarloMariaProietti 26db065
adding test + cleaning
CarloMariaProietti 2aeb956
add toStart and add docs
CarloMariaProietti eed89bc
cleaning + add a new test that DONT work
CarloMariaProietti e212f36
strategy of before/after reference not working
CarloMariaProietti a19d523
each test is working!
CarloMariaProietti 4627c60
new test
CarloMariaProietti 8b4ca9e
fixing doc
CarloMariaProietti 98cac42
change fun name + linting + improve logic
CarloMariaProietti 3c0a96c
improve syntax
CarloMariaProietti b07bad9
improving tests
CarloMariaProietti 20a7652
improve doc
CarloMariaProietti 49dd6ac
NEW APPROACH : WORK IN PROGRESS
CarloMariaProietti 800ebf9
new logic is implemented, each test works
CarloMariaProietti 1b47bfd
remove old comment
CarloMariaProietti b76dacb
add shortcut
CarloMariaProietti 906a838
remove compiler plugin support
CarloMariaProietti 0040315
new logic + new excpeption class
CarloMariaProietti dc57748
using exception class
CarloMariaProietti 5bae854
add shortcuts
CarloMariaProietti 0f6b8be
cleaning
CarloMariaProietti a306223
add shortcuts
CarloMariaProietti de0ff10
lambda is last arg
CarloMariaProietti 07a71d1
same for vararg string overload
CarloMariaProietti File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ import org.jetbrains.kotlinx.dataframe.documentation.SelectingColumns | |
import org.jetbrains.kotlinx.dataframe.impl.api.afterOrBefore | ||
import org.jetbrains.kotlinx.dataframe.impl.api.moveImpl | ||
import org.jetbrains.kotlinx.dataframe.impl.api.moveTo | ||
import org.jetbrains.kotlinx.dataframe.impl.api.moveToImpl | ||
import org.jetbrains.kotlinx.dataframe.ncol | ||
import org.jetbrains.kotlinx.dataframe.util.DEPRECATED_ACCESS_API | ||
import org.jetbrains.kotlinx.dataframe.util.MOVE_TO_LEFT | ||
|
@@ -219,6 +220,53 @@ public fun <T> DataFrame<T>.moveTo(newColumnIndex: Int, vararg columns: AnyColum | |
public fun <T> DataFrame<T>.moveTo(newColumnIndex: Int, vararg columns: KProperty<*>): DataFrame<T> = | ||
moveTo(newColumnIndex) { columns.toColumnSet() } | ||
|
||
/** | ||
* Moves the specified [columns\] to a new position specified | ||
* by [columnIndex]. If [insideGroup] is true selected columns | ||
* will be moved remaining within their [ColumnGroup], | ||
* else they will be moved to the top level. | ||
* | ||
* @include [CommonMoveToDocs] | ||
* @include [SelectingColumns.Dsl] {@include [SetMoveToOperationArg]} | ||
* ### Examples: | ||
* ```kotlin | ||
* df.moveTo(0, true) { length and age } | ||
* df.moveTo(2, false) { cols(1..5) } | ||
* ``` | ||
* @param [newColumnIndex] The index specifying the position in the [DataFrame] columns | ||
* where the selected columns will be moved. | ||
* @param [insideGroup] If true, selected columns will be moved remaining inside their group, | ||
* else they will be moved to the top level. | ||
* @param [columns\] The [Columns Selector][ColumnsSelector] used to select the columns of this [DataFrame] to move. | ||
*/ | ||
public fun <T> DataFrame<T>.moveTo( | ||
newColumnIndex: Int, | ||
insideGroup: Boolean, | ||
columns: ColumnsSelector<T, *>, | ||
): DataFrame<T> = move(columns).to(newColumnIndex, insideGroup) | ||
|
||
/** | ||
* Moves the specified [columns\] to a new position specified | ||
* by [columnIndex]. If [insideGroup] is true selected columns | ||
* will be moved remaining within their [ColumnGroup], | ||
* else they will be moved to the top level. | ||
* | ||
* @include [CommonMoveToDocs] | ||
* @include [SelectingColumns.ColumnNames] {@include [SetMoveToOperationArg]} | ||
* ### Examples: | ||
* ```kotlin | ||
* df.moveTo(0, true) { length and age } | ||
* df.moveTo(2, false) { cols(1..5) } | ||
* ``` | ||
* @param [newColumnIndex] The index specifying the position in the [DataFrame] columns | ||
* where the selected columns will be moved. | ||
* @param [insideGroup] If true, selected columns will be moved remaining inside their group, | ||
* else they will be moved to the top level. | ||
* @param [columns\] The [Columns Selector][ColumnsSelector] used to select the columns of this [DataFrame] to move. | ||
*/ | ||
public fun <T> DataFrame<T>.moveTo(newColumnIndex: Int, insideGroup: Boolean, vararg columns: String): DataFrame<T> = | ||
moveTo(newColumnIndex, insideGroup) { columns.toColumnSet() } | ||
|
||
// endregion | ||
|
||
// region moveToStart | ||
|
@@ -264,6 +312,18 @@ public fun <T> DataFrame<T>.moveToLeft(columns: ColumnsSelector<T, *>): DataFram | |
@Interpretable("MoveToStart1") | ||
public fun <T> DataFrame<T>.moveToStart(columns: ColumnsSelector<T, *>): DataFrame<T> = move(columns).toStart() | ||
|
||
/** | ||
* @include [CommonMoveToStartDocs] | ||
* @include [SelectingColumns.Dsl.WithExample] {@include [SetMoveToStartOperationArg]} | ||
* @param [columns\] The [Columns Selector][ColumnsSelector] used to select the columns of this [DataFrame] to move. | ||
* @param [insideGroup] If true, selected columns will be moved to the start remaining inside their group, | ||
* else they will be moved to the start of the top level. | ||
*/ | ||
@Refine | ||
@Interpretable("MoveToStart1") | ||
public fun <T> DataFrame<T>.moveToStart(insideGroup: Boolean, columns: ColumnsSelector<T, *>): DataFrame<T> = | ||
move(columns).toStart(insideGroup) | ||
|
||
@Deprecated(MOVE_TO_LEFT, ReplaceWith(MOVE_TO_LEFT_REPLACE), DeprecationLevel.ERROR) | ||
public fun <T> DataFrame<T>.moveToLeft(vararg columns: String): DataFrame<T> = moveToStart { columns.toColumnSet() } | ||
|
||
|
@@ -274,6 +334,16 @@ public fun <T> DataFrame<T>.moveToLeft(vararg columns: String): DataFrame<T> = m | |
*/ | ||
public fun <T> DataFrame<T>.moveToStart(vararg columns: String): DataFrame<T> = moveToStart { columns.toColumnSet() } | ||
|
||
/** | ||
* @include [CommonMoveToStartDocs] | ||
* @include [SelectingColumns.ColumnNames.WithExample] {@include [SetMoveToStartOperationArg]} | ||
* @param [columns\] The [Columns Selector][ColumnsSelector] used to select the columns of this [DataFrame] to move. | ||
* @param [insideGroup] If true, selected columns will be moved to the start remaining inside their group, | ||
* else they will be moved to the start of the top level. | ||
*/ | ||
public fun <T> DataFrame<T>.moveToStart(insideGroup: Boolean, vararg columns: String): DataFrame<T> = | ||
moveToStart(insideGroup) { columns.toColumnSet() } | ||
|
||
@Deprecated(MOVE_TO_LEFT, ReplaceWith(MOVE_TO_LEFT_REPLACE), DeprecationLevel.ERROR) | ||
@AccessApiOverload | ||
public fun <T> DataFrame<T>.moveToLeft(vararg columns: AnyColumnReference): DataFrame<T> = | ||
|
@@ -339,6 +409,18 @@ public fun <T> DataFrame<T>.moveToRight(columns: ColumnsSelector<T, *>): DataFra | |
@Interpretable("MoveToEnd1") | ||
public fun <T> DataFrame<T>.moveToEnd(columns: ColumnsSelector<T, *>): DataFrame<T> = move(columns).toEnd() | ||
|
||
/** | ||
* @include [CommonMoveToEndDocs] | ||
* @include [SelectingColumns.Dsl.WithExample] {@include [SetMoveToEndOperationArg]} | ||
* @param [columns\] The [Columns Selector][ColumnsSelector] used to select the columns of this [DataFrame] to move. | ||
* @param [insideGroup] If true, selected columns will be moved to the end remaining inside their group, | ||
* else they will be moved to the end of the top level. | ||
*/ | ||
@Refine | ||
@Interpretable("MoveToEnd1") | ||
public fun <T> DataFrame<T>.moveToEnd(insideGroup: Boolean, columns: ColumnsSelector<T, *>): DataFrame<T> = | ||
move(columns).toEnd(insideGroup) | ||
|
||
@Deprecated(MOVE_TO_RIGHT, ReplaceWith(MOVE_TO_RIGHT_REPLACE), DeprecationLevel.ERROR) | ||
public fun <T> DataFrame<T>.moveToRight(vararg columns: String): DataFrame<T> = moveToEnd { columns.toColumnSet() } | ||
|
||
|
@@ -349,6 +431,16 @@ public fun <T> DataFrame<T>.moveToRight(vararg columns: String): DataFrame<T> = | |
*/ | ||
public fun <T> DataFrame<T>.moveToEnd(vararg columns: String): DataFrame<T> = moveToEnd { columns.toColumnSet() } | ||
|
||
/** | ||
* @include [CommonMoveToEndDocs] | ||
* @include [SelectingColumns.ColumnNames.WithExample] {@include [SetMoveToEndOperationArg]} | ||
* @param [columns\] The [Columns Selector][ColumnsSelector] used to select the columns of this [DataFrame] to move. | ||
* @param [insideGroup] If true, selected columns will be moved to the end remaining inside their group, | ||
* else they will be moved to the end of the top level. | ||
*/ | ||
public fun <T> DataFrame<T>.moveToEnd(insideGroup: Boolean, vararg columns: String): DataFrame<T> = | ||
moveToEnd(insideGroup) { columns.toColumnSet() } | ||
|
||
@Deprecated(MOVE_TO_RIGHT, ReplaceWith(MOVE_TO_RIGHT_REPLACE), DeprecationLevel.ERROR) | ||
@AccessApiOverload | ||
public fun <T> DataFrame<T>.moveToRight(vararg columns: AnyColumnReference): DataFrame<T> = | ||
|
@@ -537,6 +629,32 @@ public fun <T, C> MoveClause<T, C>.under( | |
@Interpretable("MoveTo") | ||
public fun <T, C> MoveClause<T, C>.to(columnIndex: Int): DataFrame<T> = moveTo(columnIndex) | ||
|
||
/** | ||
* Moves columns, previously selected with [move] to a new position specified | ||
* by [columnIndex]. If [insideGroup] is true, selected columns will be moved remaining within their [ColumnGroup], | ||
* else they will be moved to the top level. | ||
* | ||
* Returns a new [DataFrame] with updated columns structure. | ||
* | ||
* For more information: {@include [DocumentationUrls.Move]} | ||
* | ||
* ### Examples: | ||
* ```kotlin | ||
* df.move { age and weight }.to(0, true) | ||
* df.move("age", "weight").to(2, false) | ||
* ``` | ||
* | ||
* @param [columnIndex] The index specifying the position in the [ColumnGroup] columns | ||
* where the selected columns will be moved. | ||
* | ||
* @param [insideGroup] If true, selected columns will be moved remaining inside their group, | ||
* else they will be moved to the top level. | ||
*/ | ||
@Refine | ||
@Interpretable("MoveTo") | ||
public fun <T, C> MoveClause<T, C>.to(columnIndex: Int, insideGroup: Boolean): DataFrame<T> = | ||
moveToImpl(columnIndex, insideGroup) | ||
|
||
/** | ||
* Moves columns, previously selected with [move] to the top-level within the [DataFrame]. | ||
* Moved columns name can be specified via special ColumnSelectionDsl. | ||
|
@@ -691,6 +809,28 @@ public fun <T, C> MoveClause<T, C>.toLeft(): DataFrame<T> = to(0) | |
@Interpretable("MoveToStart0") | ||
public fun <T, C> MoveClause<T, C>.toStart(): DataFrame<T> = to(0) | ||
|
||
/** | ||
* If insideGroup is true, moves columns previously selected with [move] to the start of their [ColumnGroup]. | ||
* Else, selected columns will be moved to the start of their [DataFrame] (to the top-level). | ||
* | ||
* Returns a new [DataFrame] with updated columns. | ||
* | ||
* For more information: {@include [DocumentationUrls.Move]} | ||
* | ||
* ### Examples: | ||
* ```kotlin | ||
* df.move { age and weight }.toStart(true) | ||
* df.move { colsOf<String>() }.toStart(true) | ||
* df.move("age", "weight").toStart(false) | ||
* ``` | ||
* | ||
* @param [insideGroup] If true, selected columns will be moved to the start remaining inside their group, | ||
* else they will be moved to the start on top level. | ||
*/ | ||
@Refine | ||
@Interpretable("MoveToStart0") | ||
public fun <T, C> MoveClause<T, C>.toStart(insideGroup: Boolean): DataFrame<T> = to(0, insideGroup) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh, please keep @Refine
@Interpretable("MoveToStart0") I will add compiler plugin for this variant of the function. It can use the same interpreter as |
||
|
||
@Deprecated(TO_RIGHT, ReplaceWith(TO_RIGHT_REPLACE), DeprecationLevel.ERROR) | ||
public fun <T, C> MoveClause<T, C>.toRight(): DataFrame<T> = to(df.ncol) | ||
|
||
|
@@ -712,6 +852,28 @@ public fun <T, C> MoveClause<T, C>.toRight(): DataFrame<T> = to(df.ncol) | |
@Interpretable("MoveToEnd0") | ||
public fun <T, C> MoveClause<T, C>.toEnd(): DataFrame<T> = to(df.ncol) | ||
|
||
/** | ||
* If insideGroup is true, moves columns previously selected with [move] to the end of their [ColumnGroup]. | ||
* Else, selected columns will be moved to the end of their [DataFrame] (to the top-level). | ||
* | ||
* Returns a new [DataFrame] with updated columns. | ||
* | ||
* For more information: {@include [DocumentationUrls.Move]} | ||
* | ||
* ### Examples: | ||
* ```kotlin | ||
* df.move { age and weight }.toEnd(true) | ||
* df.move { colsOf<String>() }.toEnd(true) | ||
* df.move("age", "weight").toEnd(false) | ||
* ``` | ||
* | ||
* @param [insideGroup] If true, selected columns will be moved to the end remaining inside their group, | ||
* else they will be moved to the end on top level. | ||
*/ | ||
@Refine | ||
@Interpretable("MoveToEnd0") | ||
public fun <T, C> MoveClause<T, C>.toEnd(insideGroup: Boolean): DataFrame<T> = to(df.ncol, insideGroup) | ||
|
||
/** | ||
* An intermediate class used in the [move] operation. | ||
* | ||
|
8 changes: 8 additions & 0 deletions
8
.../kotlin/org/jetbrains/kotlinx/dataframe/exceptions/ColumnsWithDifferentParentException.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.jetbrains.kotlinx.dataframe.exceptions | ||
|
||
public class ColumnsWithDifferentParentException(message: String) : | ||
IllegalArgumentException(), | ||
DataFrameError { | ||
|
||
override val message: String = message | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.