Skip to content

Commit b289573

Browse files
author
hare
committed
add edge case
1 parent 94641c9 commit b289573

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

dataframe-excel/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/xlsx.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public fun DataFrame.Companion.readExcel(
331331
}
332332

333333
else -> {
334-
val notEmptyRow = sheet.rowIterator().asSequence().find { it != null }
334+
val notEmptyRow = sheet.rowIterator().asSequence().maxByOrNull { it.lastCellNum }
335335
checkNotNull(notEmptyRow) {
336336
"There are no defined cells"
337337
}

dataframe-excel/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/XlsxTest.kt

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -204,40 +204,24 @@ class XlsxTest {
204204
fun `read with default header unstructured excel file`() {
205205
val df = DataFrame.readExcel(
206206
testResource("unstructured_example.xlsx"),
207-
withDefaultHeader = true,
207+
firstRowIsHeader = false,
208208
)
209-
df.columnNames() shouldBe
210-
listOf(
211-
"A",
212-
"B",
213-
"C",
214-
"D",
215-
"E",
216-
"F",
217-
"G",
218-
"H",
219-
"I",
220-
)
209+
df.columnNames() shouldBe listOf("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")
221210
}
222211

223212
@Test
224213
fun `should work read with default header unstructured excel file with skipRow params`() {
225214
val df = DataFrame.readExcel(
226215
testResource("unstructured_example.xlsx"),
227-
withDefaultHeader = true,
228-
skipRows = 1,
216+
firstRowIsHeader = false,
217+
skipRows = 2,
218+
rowsCount = 1,
219+
)
220+
221+
df shouldBe dataFrameOf(
222+
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
223+
)(
224+
"Field 3: ", "", "TEAM 1", "", "", "", "", "Staff Code:", "Staff 1", "",
229225
)
230-
df.columnNames() shouldBe
231-
listOf(
232-
"A",
233-
"B",
234-
"C",
235-
"D",
236-
"E",
237-
"F",
238-
"G",
239-
"H",
240-
"I",
241-
)
242226
}
243227
}
Binary file not shown.

0 commit comments

Comments
 (0)