Skip to content

Commit 4bbe272

Browse files
committed
Support classes with no public properties in toDataFrame converter
1 parent 5bcff90 commit 4bbe272

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/DataFrameImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal open class DataFrameImpl<T>(cols: List<AnyCol>, val nrow: Int) : DataFr
3535
// check that column sizes are equal
3636
val invalidSizeColumns = cols.filter { it.size != nrow }
3737
require(invalidSizeColumns.isEmpty()) {
38-
"Unequal column sizes:\n${cols.joinToString("\n") { it.name + ": " + it.size }}"
38+
"Unequal column sizes. Expected rows count = $nrow, but was:\n${cols.joinToString("\n") { it.name + ": " + it.size }}"
3939
}
4040

4141
// check that column names are unique

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,7 @@ internal fun convertToDataFrame(
204204
}
205205
}
206206
}
207-
return dataFrameOf(columns)
207+
return if (columns.isEmpty()) {
208+
DataFrame.empty(data.count())
209+
} else dataFrameOf(columns)
208210
}

tests/src/test/kotlin/org/jetbrains/kotlinx/dataframe/api/toDataFrame.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,17 @@ class CreateDataFrameTests {
116116
it.kind shouldBe ColumnKind.Value
117117
}
118118
}
119+
120+
@Test
121+
fun `convert type with no properties`() {
122+
class Child
123+
class Entry(val a: Int, val child: Child)
124+
125+
val df = listOf(Entry(1, Child())).toDataFrame(depth = 100)
126+
df.rowsCount() shouldBe 1
127+
128+
val childCol = df[Entry::child]
129+
childCol.kind() shouldBe ColumnKind.Group
130+
childCol.asColumnGroup().columnsCount() shouldBe 0
131+
}
119132
}

0 commit comments

Comments
 (0)