Skip to content

Commit ef076de

Browse files
committed
Don't fail on missing columns in remove.
1 parent 8d34d6c commit ef076de

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/merge.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public fun <T, C, R> Merge<T, C, R>.into(path: ColumnPath): DataFrame<T> {
6464
if (mergePath != path) {
6565
// target path existed before merge, but
6666
// it may have already been removed
67-
res = res.removeImpl(true) { path }.df.move(mergePath).into { path }
67+
res = res.removeImpl(allowMissingColumns = true) { path }.df.move(mergePath).into { path }
6868
}
6969
return res
7070
}

src/main/kotlin/org/jetbrains/kotlinx/dataframe/api/remove.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlin.reflect.KProperty
1010

1111
// region DataFrame
1212

13-
public fun <T> DataFrame<T>.remove(columns: ColumnsSelector<T, *>): DataFrame<T> = removeImpl(columns = columns).df
13+
public fun <T> DataFrame<T>.remove(columns: ColumnsSelector<T, *>): DataFrame<T> = removeImpl(allowMissingColumns = true, columns = columns).df
1414
public fun <T> DataFrame<T>.remove(vararg columns: KProperty<*>): DataFrame<T> = remove { columns.toColumns() }
1515
public fun <T> DataFrame<T>.remove(vararg columns: String): DataFrame<T> = remove { columns.toColumns() }
1616
public fun <T> DataFrame<T>.remove(vararg columns: Column): DataFrame<T> = remove { columns.toColumns() }

src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/remove.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,30 @@ import org.junit.Test
66

77
class RemoveTests {
88

9+
val df = dataFrameOf("a", "b")(1, 2)
10+
val b by column<Int>()
11+
data class C(val b: Int)
12+
13+
@Test
14+
fun `simple remove`() {
15+
val e = df.select("a")
16+
df.remove("b") shouldBe e
17+
df.remove { b } shouldBe e
18+
df.remove(C::b) shouldBe e
19+
}
20+
921
@Test
1022
fun `remove renamed`() {
11-
val df = dataFrameOf("a", "b")(1, 2)
1223
val (_, removed) = df.removeImpl { "a" named "c" }
1324
removed[0].data.column!!.name shouldBe "c"
1425
}
26+
27+
@Test
28+
fun `remove missing column`(){
29+
val d = df.remove { b }
30+
31+
d.remove("b") shouldBe d
32+
d.remove { b } shouldBe d
33+
d.remove(C::b) shouldBe d
34+
}
1535
}

0 commit comments

Comments
 (0)