Skip to content

Commit 45cedfd

Browse files
move impl fixes
1 parent 46392c3 commit 45cedfd

File tree

2 files changed

+9
-21
lines changed
  • core/src
    • main/kotlin/org/jetbrains/kotlinx/dataframe/impl/api
    • test/kotlin/org/jetbrains/kotlinx/dataframe/api

2 files changed

+9
-21
lines changed

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

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,13 @@ internal fun <T, C> MoveClause<T, C>.afterOrBefore(column: ColumnSelector<T, *>,
4646
val refNode = removeRoot.getOrPut(targetPath) {
4747
val path = it.asList()
4848

49-
// Find the group reference (if any) and adjust the path
50-
val groupRefIndex = path.indexOfFirst { it.isEmpty() }
49+
// Get parent of a target path
50+
val effectivePath = path.dropLast(1)
5151

52-
// Calculate effective path and column name based on group reference
53-
val effectivePath = if (groupRefIndex >= 0) {
54-
// Nested column reference
55-
path.take(groupRefIndex)
56-
} else {
57-
path.dropLast(1)
58-
}
59-
60-
val columnName = if (groupRefIndex >= 0) {
61-
// Use the next segment after group reference, or previous if no next segment
62-
path.getOrNull(groupRefIndex + 1) ?: path[groupRefIndex - 1]
63-
} else {
64-
path.last()
65-
}
52+
// Get column name (last segment)
53+
val columnName = path.last()
6654

67-
// Get the parent group using ColumnPath
55+
// Get the parent
6856
val parent = if (effectivePath.isEmpty()) {
6957
df
7058
} else {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,23 +133,23 @@ class MoveTests {
133133
// Simple case: direct parent-child relationship
134134
shouldThrow<IllegalArgumentException> {
135135
grouped.move("a").after { "a"["b"] }
136-
}.message shouldBe "Cannot move column 'a' after its child column 'a/b'"
136+
}.message shouldBe "Cannot move column 'a' after its own child column 'a/b'"
137137

138138
// Nested case: deeper parent-child relationship
139139
shouldThrow<IllegalArgumentException> {
140140
grouped.move("a").after { "a"["c"]["d"] }
141-
}.message shouldBe "Cannot move column 'a' after its child column 'a/c/d'"
141+
}.message shouldBe "Cannot move column 'a' after its own child column 'a/c/d'"
142142

143143
// Group case: moving group after its nested column
144144
shouldThrow<IllegalArgumentException> {
145145
grouped.move { "a"["c"] }.after { "a"["c"]["d"] }
146-
}.message shouldBe "Cannot move column 'a/c' after its child column 'a/c/d'"
146+
}.message shouldBe "Cannot move column 'a/c' after its own child column 'a/c/d'"
147147
}
148148

149149
@Test
150150
fun `should throw when moving column after itself`() {
151151
shouldThrow<IllegalArgumentException> {
152152
grouped.move { "a"["b"] }.after { "a"["b"] }
153-
}.message shouldBe "Cannot move column 'a/b' after its child column 'a/b'"
153+
}.message shouldBe "Cannot move column 'a/b' after its own child column 'a/b'"
154154
}
155155
}

0 commit comments

Comments
 (0)