Skip to content

Move/Insert After fix #1092

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

Merged
merged 8 commits into from
Mar 17, 2025
Merged

Move/Insert After fix #1092

merged 8 commits into from
Mar 17, 2025

Conversation

AndreiKingsley
Copy link
Collaborator

fun box(): String {
val df = dataFrameOf("a", "b", "c")(1, 2, 3, 4, 5, 6)
val grouped = df.group { a and b }.into("g")
grouped.move { g.a }.after { g.b }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused line

@@ -527,6 +527,7 @@ class DataFrameTreeTests : BaseTest() {
@Test
fun moveAfter() {
val moved = typed2.move { age }.after { nameAndCity.name }
println(moved)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused line i think

Copy link
Collaborator

@koperagen koperagen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to set milestone, assignee and labels for generated change log

@Jolanrensen Jolanrensen self-requested a review March 11, 2025 14:03
Copy link
Collaborator

@Jolanrensen Jolanrensen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job :) just have some questions

sourceSegments.indices.all { targetSegments[it] == sourceSegments[it] }
) {
throw IllegalArgumentException(
"Cannot move column '${sourcePath.joinToString()}' after its child column '${targetPath.joinToString()}'",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, but may be clearer if you add something like "cannot move this column into itself" or something. Took me a while to realize why you cannot move something after a child XD

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe "its own child"? is it a proper english? makes it clearer?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, i wonder what will happen if you df.move { a }.under { a.b }. Same exception as with "after"?

val parent = if (parentPath.isEmpty()) df else df.getColumnGroup(parentPath)
val index = parent.getColumnIndex(it.last())
val col = df.getColumn(index)
val path = it.toList()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be cast to List as well

val path = it.toList()

// Find the group reference (if any) and adjust the path
val groupRefIndex = path.indexOfFirst { it.isEmpty() }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is happening here? How does the first empty path piece correspond to a group node? And at which indices can this empty path piece occur?


val columnName = if (groupRefIndex >= 0) {
// Use the next segment after group reference, or previous if no next segment
path.getOrNull(groupRefIndex + 1) ?: path[groupRefIndex - 1]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this break if groupRefIndex == 0?

fun box(): String {
val df = dataFrameOf("a", "b", "c")(1, 2, 3, 4, 5, 6)

val dfWithD = df.insert("d") { b * c }.after { a }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe lint these as well? XD

@AndreiKingsley AndreiKingsley merged commit 40e1db1 into master Mar 17, 2025
4 of 5 checks passed
@AndreiKingsley AndreiKingsley deleted the move_fix branch March 17, 2025 11:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move/Insert after nested column breaks
3 participants