Skip to content

Commit f1b245e

Browse files
authored
Merge pull request #403 from Kotlin/withValue-removal
withValue() -> with { value }
2 parents b542198 + b70824e commit f1b245e

File tree

21 files changed

+46
-53
lines changed

21 files changed

+46
-53
lines changed

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ internal interface FillNulls {
3535
* | .`[notNull][org.jetbrains.kotlinx.dataframe.api.Update.notNull]` { `[rowExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenRow.RowValueExpression.WithExample]` }
3636
* | .`[perCol][org.jetbrains.kotlinx.dataframe.api.Update.perCol]` { `[colExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenColumn.ColumnExpression.WithExample]` }
3737
* | .`[perRowCol][org.jetbrains.kotlinx.dataframe.api.Update.perRowCol]` { `[rowColExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenRowAndColumn.RowColumnExpression.WithExample]` }
38-
* | .`[withValue][org.jetbrains.kotlinx.dataframe.api.Update.withValue]`(value)
3938
* | .`[withNull][org.jetbrains.kotlinx.dataframe.api.Update.withNull]`()
4039
* | .`[withZero][org.jetbrains.kotlinx.dataframe.api.Update.withZero]`()
4140
* | .`[asFrame][org.jetbrains.kotlinx.dataframe.api.Update.asFrame]` { `[dataFrameExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenDataFrame.DataFrameExpression.WithExample]` }`
@@ -239,7 +238,6 @@ internal interface FillNaNs {
239238
* | .`[notNull][org.jetbrains.kotlinx.dataframe.api.Update.notNull]` { `[rowExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenRow.RowValueExpression.WithExample]` }
240239
* | .`[perCol][org.jetbrains.kotlinx.dataframe.api.Update.perCol]` { `[colExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenColumn.ColumnExpression.WithExample]` }
241240
* | .`[perRowCol][org.jetbrains.kotlinx.dataframe.api.Update.perRowCol]` { `[rowColExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenRowAndColumn.RowColumnExpression.WithExample]` }
242-
* | .`[withValue][org.jetbrains.kotlinx.dataframe.api.Update.withValue]`(value)
243241
* | .`[withNull][org.jetbrains.kotlinx.dataframe.api.Update.withNull]`()
244242
* | .`[withZero][org.jetbrains.kotlinx.dataframe.api.Update.withZero]`()
245243
* | .`[asFrame][org.jetbrains.kotlinx.dataframe.api.Update.asFrame]` { `[dataFrameExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenDataFrame.DataFrameExpression.WithExample]` }`
@@ -413,7 +411,6 @@ internal interface FillNA {
413411
* | .`[notNull][org.jetbrains.kotlinx.dataframe.api.Update.notNull]` { `[rowExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenRow.RowValueExpression.WithExample]` }
414412
* | .`[perCol][org.jetbrains.kotlinx.dataframe.api.Update.perCol]` { `[colExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenColumn.ColumnExpression.WithExample]` }
415413
* | .`[perRowCol][org.jetbrains.kotlinx.dataframe.api.Update.perRowCol]` { `[rowColExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenRowAndColumn.RowColumnExpression.WithExample]` }
416-
* | .`[withValue][org.jetbrains.kotlinx.dataframe.api.Update.withValue]`(value)
417414
* | .`[withNull][org.jetbrains.kotlinx.dataframe.api.Update.withNull]`()
418415
* | .`[withZero][org.jetbrains.kotlinx.dataframe.api.Update.withZero]`()
419416
* | .`[asFrame][org.jetbrains.kotlinx.dataframe.api.Update.asFrame]` { `[dataFrameExpression][org.jetbrains.kotlinx.dataframe.documentation.ExpressionsGivenDataFrame.DataFrameExpression.WithExample]` }`

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public data class Update<T, C>(
5050
* | .`[notNull][Update.notNull]` { `[rowExpression][ExpressionsGivenRow.RowValueExpression.WithExample]` }
5151
* | .`[perCol][Update.perCol]` { `[colExpression][ExpressionsGivenColumn.ColumnExpression.WithExample]` }
5252
* | .`[perRowCol][Update.perRowCol]` { `[rowColExpression][ExpressionsGivenRowAndColumn.RowColumnExpression.WithExample]` }
53-
* | .`[withValue][Update.withValue]`(value)
5453
* | .`[withNull][Update.withNull]`()
5554
* | .`[withZero][Update.withZero]`()
5655
* | .`[asFrame][Update.asFrame]` { `[dataFrameExpression][ExpressionsGivenDataFrame.DataFrameExpression.WithExample]` }`
@@ -764,4 +763,5 @@ public fun <T, C> Update<T, C>.withZero(): DataFrame<T> = updateWithValuePerColu
764763
*
765764
* @param [value] The value to set the selected rows to. In contrast to [with][Update.with], this must be the same exact type.
766765
*/
766+
@Deprecated("Use with { value } instead", ReplaceWith("this.with { value }"))
767767
public fun <T, C> Update<T, C>.withValue(value: C): DataFrame<T> = with { value }

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/contains.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ContainsTests {
1717
val df = dataFrameOf("a", "b")(1, 2, 3, 4)
1818
val col = df.asColumnGroup("col")
1919
col.contains(df[0]) shouldBe true
20-
col.contains(df.update("b").withValue(0)[0]) shouldBe false
20+
col.contains(df.update("b").with { 0 }[0]) shouldBe false
2121
}
2222

2323
@Test

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/DataRowApi.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import org.jetbrains.kotlinx.dataframe.api.prev
1010
import org.jetbrains.kotlinx.dataframe.api.update
1111
import org.jetbrains.kotlinx.dataframe.api.where
1212
import org.jetbrains.kotlinx.dataframe.api.with
13-
import org.jetbrains.kotlinx.dataframe.api.withValue
1413
import org.jetbrains.kotlinx.dataframe.explainer.TransformDataFrameExpressions
1514
import org.junit.Test
1615

@@ -38,11 +37,11 @@ class DataRowApi : TestBase() {
3837
// Row condition is used to filter rows by index
3938
df.filter { index() % 5 == 0 }
4039

41-
// Row condition is used to drop rows where `age` is the same as in previous row
40+
// Row condition is used to drop rows where `age` is the same as in the previous row
4241
df.drop { diffOrNull { age } == 0 }
4342

4443
// Row condition is used to filter rows for value update
45-
df.update { weight }.where { index() > 4 && city != "Paris" }.withValue(50)
44+
df.update { weight }.where { index() > 4 && city != "Paris" }.with { 50 }
4645
// SampleEnd
4746
}
4847
}

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/samples/api/Modify.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ import org.jetbrains.kotlinx.dataframe.api.update
9595
import org.jetbrains.kotlinx.dataframe.api.where
9696
import org.jetbrains.kotlinx.dataframe.api.with
9797
import org.jetbrains.kotlinx.dataframe.api.withNull
98-
import org.jetbrains.kotlinx.dataframe.api.withValue
9998
import org.jetbrains.kotlinx.dataframe.api.withZero
10099
import org.jetbrains.kotlinx.dataframe.explainer.PluginCallbackProxy
101100
import org.jetbrains.kotlinx.dataframe.explainer.TransformDataFrameExpressions
@@ -137,7 +136,7 @@ class Modify : TestBase() {
137136
@TransformDataFrameExpressions
138137
fun updateWithConst() {
139138
// SampleStart
140-
df.update { city }.where { name.firstName == "Alice" }.withValue("Paris")
139+
df.update { city }.where { name.firstName == "Alice" }.with { "Paris" }
141140
// SampleEnd
142141
}
143142

@@ -304,7 +303,7 @@ class Modify : TestBase() {
304303
@TransformDataFrameExpressions
305304
fun fillNA() {
306305
// SampleStart
307-
df.fillNA { weight }.withValue(-1)
306+
df.fillNA { weight }.with { -1 }
308307
// SampleEnd
309308
}
310309

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/animals/AnimalsTests.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import org.jetbrains.kotlinx.dataframe.api.name
88
import org.jetbrains.kotlinx.dataframe.api.transpose
99
import org.jetbrains.kotlinx.dataframe.api.update
1010
import org.jetbrains.kotlinx.dataframe.api.value
11+
import org.jetbrains.kotlinx.dataframe.api.with
1112
import org.jetbrains.kotlinx.dataframe.api.withNull
12-
import org.jetbrains.kotlinx.dataframe.api.withValue
1313
import org.junit.Test
1414
import kotlin.reflect.typeOf
1515

@@ -38,7 +38,7 @@ class AnimalsTests {
3838

3939
@Test
4040
fun `mean of empty`() {
41-
val cleared = df.update { age }.withValue(Double.NaN).update { visits }.withNull()
41+
val cleared = df.update { age }.with { Double.NaN }.update { visits }.withNull()
4242
val mean = cleared.mean()
4343
mean[age] shouldBe Double.NaN
4444
(mean[visits.name()] as Double).isNaN() shouldBe true

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/testSets/person/DataFrameTests.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,14 @@ class DataFrameTests : BaseTest() {
238238

239239
@Test
240240
fun `update cells by index`() {
241-
val res = typed.update { age }.at(2, 4).withValue(100)
241+
val res = typed.update { age }.at(2, 4).with { 100 }
242242
val expected = typed.rows().map { if (it.index == 2 || it.index == 4) 100 else it.age }
243243
res.age.toList() shouldBe expected
244244
}
245245

246246
@Test
247247
fun `update cells by index range`() {
248-
val res = typed.update { age }.at(2..4).withValue(100)
248+
val res = typed.update { age }.at(2..4).with { 100 }
249249
val expected = typed.rows().map { if (it.index in 2..4) 100 else it.age }
250250
res.age.toList() shouldBe expected
251251
}
@@ -257,13 +257,13 @@ class DataFrameTests : BaseTest() {
257257
this["weight"].toList() shouldBe expected
258258
}
259259

260-
typed.fillNulls { weight }.withValue(0).check()
261-
typed.fillNulls(typed.weight).withValue(0).check()
260+
typed.fillNulls { weight }.with { 0 }.check()
261+
typed.fillNulls(typed.weight).with { 0 }.check()
262262

263-
df.fillNulls { weight }.withValue(0).check()
264-
df.fillNulls(weight).withValue(0).check()
263+
df.fillNulls { weight }.with { 0 }.check()
264+
df.fillNulls(weight).with { 0 }.check()
265265

266-
df.fillNulls("weight").withValue(0).check()
266+
df.fillNulls("weight").with { 0 }.check()
267267

268268
typed.fillNulls { weight }.withZero().check()
269269
typed.fillNulls { weight }.withZero().check()
@@ -1337,7 +1337,7 @@ class DataFrameTests : BaseTest() {
13371337

13381338
@Test
13391339
fun corr() {
1340-
val fixed = typed.fillNulls { weight }.withValue(60)
1340+
val fixed = typed.fillNulls { weight }.with { 60 }
13411341
val res = fixed.corr()
13421342
res.ncol shouldBe 3
13431343
res.nrow shouldBe 2
@@ -1526,7 +1526,7 @@ class DataFrameTests : BaseTest() {
15261526
@Test
15271527
fun `update nullable column with not null`() {
15281528
val df = dataFrameOf("name", "value")("Alice", 1, null, 2)
1529-
df.update("name").at(0).withValue("ALICE")
1529+
df.update("name").at(0).with { "ALICE" }
15301530
}
15311531

15321532
@Test(expected = IllegalArgumentException::class)
@@ -1905,7 +1905,7 @@ class DataFrameTests : BaseTest() {
19051905
@Test
19061906
fun `find the longest string`() {
19071907
val longestCityName = "Taumatawhakatangihangakoauauotamateaturipukakapikimaungahoronukupokaiwhenuakitanatahu"
1908-
val updated = typed.update { city }.where { it == "Dubai" }.withValue(longestCityName)
1908+
val updated = typed.update { city }.where { it == "Dubai" }.with { longestCityName }
19091909
updated.valuesNotNull { colsOf<String?>() }.maxByOrNull { it.length } shouldBe longestCityName
19101910
}
19111911

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public data class Update<T, C>(
5050
* | .`[notNull][Update.notNull]` { `[rowExpression][ExpressionsGivenRow.RowValueExpression.WithExample]` }
5151
* | .`[perCol][Update.perCol]` { `[colExpression][ExpressionsGivenColumn.ColumnExpression.WithExample]` }
5252
* | .`[perRowCol][Update.perRowCol]` { `[rowColExpression][ExpressionsGivenRowAndColumn.RowColumnExpression.WithExample]` }
53-
* | .`[withValue][Update.withValue]`(value)
5453
* | .`[withNull][Update.withNull]`()
5554
* | .`[withZero][Update.withZero]`()
5655
* | .`[asFrame][Update.asFrame]` { `[dataFrameExpression][ExpressionsGivenDataFrame.DataFrameExpression.WithExample]` }`
@@ -453,4 +452,5 @@ public fun <T, C> Update<T, C>.withZero(): DataFrame<T> = updateWithValuePerColu
453452
*
454453
* @param [value] The value to set the selected rows to. In contrast to [with][Update.with], this must be the same exact type.
455454
*/
455+
@Deprecated("Use with { value } instead", ReplaceWith("this.with { value }"))
456456
public fun <T, C> Update<T, C>.withValue(value: C): DataFrame<T> = with { value }

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ContainsTests {
1717
val df = dataFrameOf("a", "b")(1, 2, 3, 4)
1818
val col = df.asColumnGroup("col")
1919
col.contains(df[0]) shouldBe true
20-
col.contains(df.update("b").withValue(0)[0]) shouldBe false
20+
col.contains(df.update("b").with { 0 }[0]) shouldBe false
2121
}
2222

2323
@Test

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import org.jetbrains.kotlinx.dataframe.api.prev
1010
import org.jetbrains.kotlinx.dataframe.api.update
1111
import org.jetbrains.kotlinx.dataframe.api.where
1212
import org.jetbrains.kotlinx.dataframe.api.with
13-
import org.jetbrains.kotlinx.dataframe.api.withValue
1413
import org.jetbrains.kotlinx.dataframe.explainer.TransformDataFrameExpressions
1514
import org.junit.Test
1615

@@ -38,11 +37,11 @@ class DataRowApi : TestBase() {
3837
// Row condition is used to filter rows by index
3938
df.filter { index() % 5 == 0 }
4039

41-
// Row condition is used to drop rows where `age` is the same as in previous row
40+
// Row condition is used to drop rows where `age` is the same as in the previous row
4241
df.drop { diffOrNull { age } == 0 }
4342

4443
// Row condition is used to filter rows for value update
45-
df.update { weight }.where { index() > 4 && city != "Paris" }.withValue(50)
44+
df.update { weight }.where { index() > 4 && city != "Paris" }.with { 50 }
4645
// SampleEnd
4746
}
4847
}

0 commit comments

Comments
 (0)