Skip to content

Commit 1a0007f

Browse files
authored
Added nullability support for the describe() (#384)
* Added fix and test * Generated files
1 parent 8979f3e commit 1a0007f

File tree

4 files changed

+44
-2
lines changed
  • core
    • generated-sources/src
    • src

4 files changed

+44
-2
lines changed

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ internal fun describeImpl(cols: List<AnyCol>): DataFrame<ColumnDescription> {
6464
if (hasLongPaths) {
6565
ColumnDescription::path from { it.path() }
6666
}
67-
ColumnDescription::type from { it.type.jvmErasure.simpleName }
67+
ColumnDescription::type from { buildTypeName(it) }
6868
ColumnDescription::count from { it.size }
6969
ColumnDescription::unique from { it.countDistinct() }
7070
ColumnDescription::nulls from { it.values.count { it == null } }
@@ -91,3 +91,12 @@ internal fun describeImpl(cols: List<AnyCol>): DataFrame<ColumnDescription> {
9191

9292
return df.cast()
9393
}
94+
95+
private fun buildTypeName(it: AnyCol): String {
96+
val rawJavaType = it.type.jvmErasure.simpleName.toString()
97+
return if (it.type.isMarkedNullable) {
98+
"$rawJavaType?"
99+
} else {
100+
rawJavaType
101+
}
102+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,18 @@ class DataFrameTests : BaseTest() {
21702170
fun describe() {
21712171
val desc = typed.group { age and weight }.into("info").groupBy { city }.toDataFrame().describe()
21722172
desc.nrow shouldBe typed.ncol + 1
2173+
desc["type"][0] shouldBe "String?"
2174+
desc["path"][1] shouldBe listOf("group", "name")
2175+
desc["name"][0] shouldBe "city"
2176+
desc["count"][3] shouldBe 7
2177+
desc["unique"][4] shouldBe 6
2178+
desc["nulls"][3] shouldBe 2
2179+
desc["top"][0] shouldBe "London"
2180+
desc["mean"][2] shouldBe 28.571428571428573
2181+
desc["std"][2] shouldBe 11.073348527841414
2182+
desc["min"][2] shouldBe 15
2183+
desc["median"][2] shouldBe 30
2184+
desc["max"][2] shouldBe 45
21732185
desc.print()
21742186
}
21752187

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ internal fun describeImpl(cols: List<AnyCol>): DataFrame<ColumnDescription> {
6464
if (hasLongPaths) {
6565
ColumnDescription::path from { it.path() }
6666
}
67-
ColumnDescription::type from { it.type.jvmErasure.simpleName }
67+
ColumnDescription::type from { buildTypeName(it) }
6868
ColumnDescription::count from { it.size }
6969
ColumnDescription::unique from { it.countDistinct() }
7070
ColumnDescription::nulls from { it.values.count { it == null } }
@@ -91,3 +91,12 @@ internal fun describeImpl(cols: List<AnyCol>): DataFrame<ColumnDescription> {
9191

9292
return df.cast()
9393
}
94+
95+
private fun buildTypeName(it: AnyCol): String {
96+
val rawJavaType = it.type.jvmErasure.simpleName.toString()
97+
return if (it.type.isMarkedNullable) {
98+
"$rawJavaType?"
99+
} else {
100+
rawJavaType
101+
}
102+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,6 +2170,18 @@ class DataFrameTests : BaseTest() {
21702170
fun describe() {
21712171
val desc = typed.group { age and weight }.into("info").groupBy { city }.toDataFrame().describe()
21722172
desc.nrow shouldBe typed.ncol + 1
2173+
desc["type"][0] shouldBe "String?"
2174+
desc["path"][1] shouldBe listOf("group", "name")
2175+
desc["name"][0] shouldBe "city"
2176+
desc["count"][3] shouldBe 7
2177+
desc["unique"][4] shouldBe 6
2178+
desc["nulls"][3] shouldBe 2
2179+
desc["top"][0] shouldBe "London"
2180+
desc["mean"][2] shouldBe 28.571428571428573
2181+
desc["std"][2] shouldBe 11.073348527841414
2182+
desc["min"][2] shouldBe 15
2183+
desc["median"][2] shouldBe 30
2184+
desc["max"][2] shouldBe 45
21732185
desc.print()
21742186
}
21752187

0 commit comments

Comments
 (0)