Skip to content

Commit 8889e13

Browse files
committed
Merge branch 'master' into statistics-fixes
2 parents b64791f + 1042dcb commit 8889e13

File tree

211 files changed

+2646
-545
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+2646
-545
lines changed

core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ dependencies {
8787
}
8888
testImplementation(libs.kotlin.scriptingJvm)
8989
testImplementation(libs.jsoup)
90+
testImplementation(libs.sl4jsimple)
9091
}
9192

9293
val samplesImplementation by configurations.getting {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import org.jetbrains.kotlinx.dataframe.ColumnsSelector
55
import org.jetbrains.kotlinx.dataframe.DataColumn
66
import org.jetbrains.kotlinx.dataframe.DataFrame
77
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
8+
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
9+
import org.jetbrains.kotlinx.dataframe.annotations.Refine
810
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
911
import org.jetbrains.kotlinx.dataframe.impl.nameGenerator
1012
import kotlin.reflect.KProperty
@@ -50,6 +52,8 @@ public fun <T> DataColumn<T>.valueCounts(
5052

5153
// region DataFrame
5254

55+
@Refine
56+
@Interpretable("ValueCounts")
5357
public fun <T> DataFrame<T>.valueCounts(
5458
sort: Boolean = true,
5559
ascending: Boolean = false,

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/columns/ColumnAccessorImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ internal class ColumnAccessorImpl<T>(val path: ColumnPath) : ColumnAccessor<T> {
4343
override fun getValue(row: AnyRow) = path.getValue(row) as T
4444

4545
override fun getValueOrNull(row: AnyRow) = path.getValueOrNull(row) as T
46+
47+
override fun toString(): String = path().toString()
4648
}

core/generated-sources/src/main/kotlin/org/jetbrains/kotlinx/dataframe/jupyter/Integration.kt

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import org.jetbrains.kotlinx.jupyter.api.libraries.JupyterIntegration
5757
import org.jetbrains.kotlinx.jupyter.api.libraries.resources
5858
import kotlin.reflect.KClass
5959
import kotlin.reflect.KProperty
60-
import kotlin.reflect.KType
6160
import kotlin.reflect.full.isSubtypeOf
6261

6362
/** Users will get an error if their Kotlin Jupyter kernel is older than this version. */
@@ -70,29 +69,6 @@ internal class Integration(private val notebook: Notebook, private val options:
7069

7170
val version = options["v"]
7271

73-
private fun KotlinKernelHost.execute(codeWithConverter: CodeWithConverter, argument: String): VariableName? {
74-
val code = codeWithConverter.with(argument)
75-
return if (code.isNotBlank()) {
76-
val result = execute(code)
77-
if (codeWithConverter.hasConverter) {
78-
result.name
79-
} else {
80-
null
81-
}
82-
} else {
83-
null
84-
}
85-
}
86-
87-
private fun KotlinKernelHost.execute(
88-
codeWithConverter: CodeWithConverter,
89-
property: KProperty<*>,
90-
type: KType,
91-
): VariableName? {
92-
val variableName = "(${property.name}${if (property.returnType.isMarkedNullable) "!!" else ""} as $type)"
93-
return execute(codeWithConverter, variableName)
94-
}
95-
9672
private fun KotlinKernelHost.updateImportDataSchemaVariable(
9773
importDataSchema: ImportDataSchema,
9874
property: KProperty<*>,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.jetbrains.kotlinx.dataframe.jupyter
2+
3+
import org.jetbrains.kotlinx.dataframe.codeGen.CodeWithConverter
4+
import org.jetbrains.kotlinx.jupyter.api.KotlinKernelHost
5+
import org.jetbrains.kotlinx.jupyter.api.VariableName
6+
import kotlin.reflect.KProperty
7+
import kotlin.reflect.KType
8+
9+
internal fun KotlinKernelHost.execute(codeWithConverter: CodeWithConverter, argument: String): VariableName? {
10+
val code = codeWithConverter.with(argument)
11+
return if (code.isNotBlank()) {
12+
val result = execute(code)
13+
if (codeWithConverter.hasConverter) {
14+
result.name
15+
} else {
16+
null
17+
}
18+
} else {
19+
null
20+
}
21+
}
22+
23+
internal fun KotlinKernelHost.execute(
24+
codeWithConverter: CodeWithConverter,
25+
property: KProperty<*>,
26+
type: KType,
27+
): VariableName? {
28+
val variableName = "(${property.name}${if (property.returnType.isMarkedNullable) "!!" else ""} as $type)"
29+
return execute(codeWithConverter, variableName)
30+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class GetTests {
4949
shouldThrow<IllegalArgumentException> { row.getValue(c) }
5050
shouldThrow<IllegalArgumentException> { row.getValue(A::c) }
5151

52+
val throwable = shouldThrow<IllegalArgumentException> { df[column<Int>("c")] }
53+
throwable.message shouldContain "Column not found: '[c]'"
54+
5255
val added = df.add(A::c) { "3" }[0]
5356

5457
shouldThrow<ClassCastException> { added.getValue(c) + 1 }

core/generated-sources/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/FastDoubleParserTests.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,21 @@ import org.junit.Test
99
import java.text.NumberFormat
1010
import java.util.Locale
1111

12-
private const val LOG_LEVEL = "org.slf4j.simpleLogger.defaultLogLevel"
13-
1412
class FastDoubleParserTests {
1513

14+
private val logLevel = "org.slf4j.simpleLogger.log.${FastDoubleParser::class.qualifiedName}"
1615
private var loggerBefore: String? = null
1716

1817
@Before
1918
fun setLogger() {
20-
loggerBefore = System.getProperty(LOG_LEVEL)
21-
System.setProperty(LOG_LEVEL, "debug")
19+
loggerBefore = System.getProperty(logLevel)
20+
System.setProperty(logLevel, "debug")
2221
}
2322

2423
@After
2524
fun restoreLogger() {
2625
if (loggerBefore != null) {
27-
System.setProperty(LOG_LEVEL, loggerBefore)
26+
System.setProperty(logLevel, loggerBefore)
2827
}
2928
}
3029

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

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,4 +1464,63 @@ class Modify : TestBase() {
14641464
}
14651465
// SampleEnd
14661466
}
1467+
1468+
@Test
1469+
@TransformDataFrameExpressions
1470+
fun rename_properties() {
1471+
// SampleStart
1472+
df.rename { name }.into("fullName")
1473+
// SampleEnd
1474+
}
1475+
1476+
@Test
1477+
@TransformDataFrameExpressions
1478+
fun rename_accessors() {
1479+
// SampleStart
1480+
val name by columnGroup()
1481+
df.rename(name).into("fullName")
1482+
// SampleEnd
1483+
}
1484+
1485+
@Test
1486+
@TransformDataFrameExpressions
1487+
fun rename_strings() {
1488+
// SampleStart
1489+
df.rename("name").into("fullName")
1490+
// SampleEnd
1491+
}
1492+
1493+
@Test
1494+
@TransformDataFrameExpressions
1495+
fun renameExpression_properties() {
1496+
// SampleStart
1497+
df.rename { age }.into {
1498+
val mean = it.data.mean()
1499+
"age [mean = $mean]"
1500+
}
1501+
// SampleEnd
1502+
}
1503+
1504+
@Test
1505+
@TransformDataFrameExpressions
1506+
fun renameExpression_accessors() {
1507+
// SampleStart
1508+
val age by column<Int>()
1509+
df.rename(age).into {
1510+
val mean = it.data.mean()
1511+
"age [mean = $mean]"
1512+
}
1513+
// SampleEnd
1514+
}
1515+
1516+
@Test
1517+
@TransformDataFrameExpressions
1518+
fun renameExpression_strings() {
1519+
// SampleStart
1520+
df.rename("age").into {
1521+
val mean = it.data.cast<Int>().mean()
1522+
"age [mean = $mean]"
1523+
}
1524+
// SampleEnd
1525+
}
14671526
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import org.jetbrains.kotlinx.dataframe.ColumnsSelector
55
import org.jetbrains.kotlinx.dataframe.DataColumn
66
import org.jetbrains.kotlinx.dataframe.DataFrame
77
import org.jetbrains.kotlinx.dataframe.annotations.DataSchema
8+
import org.jetbrains.kotlinx.dataframe.annotations.Interpretable
9+
import org.jetbrains.kotlinx.dataframe.annotations.Refine
810
import org.jetbrains.kotlinx.dataframe.columns.toColumnSet
911
import org.jetbrains.kotlinx.dataframe.impl.nameGenerator
1012
import kotlin.reflect.KProperty
@@ -50,6 +52,8 @@ public fun <T> DataColumn<T>.valueCounts(
5052

5153
// region DataFrame
5254

55+
@Refine
56+
@Interpretable("ValueCounts")
5357
public fun <T> DataFrame<T>.valueCounts(
5458
sort: Boolean = true,
5559
ascending: Boolean = false,

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/columns/ColumnAccessorImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ internal class ColumnAccessorImpl<T>(val path: ColumnPath) : ColumnAccessor<T> {
4343
override fun getValue(row: AnyRow) = path.getValue(row) as T
4444

4545
override fun getValueOrNull(row: AnyRow) = path.getValueOrNull(row) as T
46+
47+
override fun toString(): String = path().toString()
4648
}

0 commit comments

Comments
 (0)