Skip to content

Commit 8e968ba

Browse files
committed
fixup! Improve missing column error message in CS DSL
1 parent 788bb89 commit 8e968ba

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,21 @@ internal open class DataFrameReceiver<T>(
5959
else -> this
6060
}
6161

62+
// Context:
6263
// it's strange that we have to reverse-search why the column is missing
6364
// would be nice to "fail fast" exactly where resolve failed, knowing the current path and parent.
6465
// but it's very unclear what to do with resolveSingle.
6566
// at first glance: a lot of changes.
67+
@Suppress("FoldInitializerAndIfToElvis")
6668
private fun formatMissingColumnMessage(path: ColumnPath): String {
6769
val fullPath = path.joinToString()
6870

69-
for (index in path.indices) {
70-
val currentPath = path.slice(0..index).toPath()
71+
for (depth in path.indices) {
72+
val currentPath = path.slice(0..depth).toPath()
7173
val currentPathString = currentPath.joinToString()
7274
val column = df.getColumnOrNull(currentPath)
7375
if (column == null) {
74-
return if (index == 0) {
76+
return if (depth == 0) {
7577
"Column '$currentPathString' not found among ${df.columnNames()}."
7678
} else {
7779
val parentPath = currentPath.dropLast()
@@ -85,7 +87,7 @@ internal open class DataFrameReceiver<T>(
8587
}
8688
}
8789

88-
if (index != path.lastIndex) {
90+
if (depth != path.lastIndex) {
8991
if (!column.isColumnGroup()) {
9092
return "Column '$fullPath' cannot be resolved: '$currentPathString' is not a column group."
9193
}

0 commit comments

Comments
 (0)