Skip to content

Commit 94641c9

Browse files
author
hare
committed
Clearly modify kdoc and argument name
1 parent 0d08506 commit 94641c9

File tree

1 file changed

+48
-48
lines changed
  • dataframe-excel/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io

1 file changed

+48
-48
lines changed

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

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ private fun setWorkbookTempDirectory() {
9393
* @param skipRows number of rows before header
9494
* @param rowsCount number of rows to read.
9595
* @param nameRepairStrategy handling of column names.
96-
* @param withDefaultHeader make default header
9796
* The default behavior is [NameRepairStrategy.CHECK_UNIQUE].
98-
* However, when withDefaultHeader is set to true,
99-
* it operates as [NameRepairStrategy.MAKE_UNIQUE],
100-
* ensuring unique column names are generated for unstructured data.
97+
* @param firstRowIsHeader when set to true, it will take the first row (after skipRows) as the header.
98+
* when set to false, it operates as [NameRepairStrategy.MAKE_UNIQUE],
99+
* ensuring unique column names will make the columns be named according to excel columns, like "A", "B", "C" etc.
100+
* for unstructured data.
101101
*/
102102
public fun DataFrame.Companion.readExcel(
103103
url: URL,
@@ -107,7 +107,7 @@ public fun DataFrame.Companion.readExcel(
107107
stringColumns: StringColumns? = null,
108108
rowsCount: Int? = null,
109109
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
110-
withDefaultHeader: Boolean = false,
110+
firstRowIsHeader: Boolean = true,
111111
): AnyFrame {
112112
setWorkbookTempDirectory()
113113
val wb = WorkbookFactory.create(url.openStream())
@@ -120,7 +120,7 @@ public fun DataFrame.Companion.readExcel(
120120
stringColumns?.toFormattingOptions(),
121121
rowsCount,
122122
nameRepairStrategy,
123-
withDefaultHeader,
123+
firstRowIsHeader,
124124
)
125125
}
126126
}
@@ -133,11 +133,11 @@ public fun DataFrame.Companion.readExcel(
133133
* @param skipRows number of rows before header
134134
* @param rowsCount number of rows to read.
135135
* @param nameRepairStrategy handling of column names.
136-
* @param withDefaultHeader make default header
137136
* The default behavior is [NameRepairStrategy.CHECK_UNIQUE].
138-
* However, when withDefaultHeader is set to true,
139-
* it operates as [NameRepairStrategy.MAKE_UNIQUE],
140-
* ensuring unique column names are generated for unstructured data.
137+
* @param firstRowIsHeader when set to true, it will take the first row (after skipRows) as the header.
138+
* when set to false, it operates as [NameRepairStrategy.MAKE_UNIQUE],
139+
* ensuring unique column names will make the columns be named according to excel columns, like "A", "B", "C" etc.
140+
* for unstructured data.
141141
*/
142142
public fun DataFrame.Companion.readExcel(
143143
file: File,
@@ -147,7 +147,7 @@ public fun DataFrame.Companion.readExcel(
147147
stringColumns: StringColumns? = null,
148148
rowsCount: Int? = null,
149149
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
150-
withDefaultHeader: Boolean = false,
150+
firstRowIsHeader: Boolean = true,
151151
): AnyFrame {
152152
setWorkbookTempDirectory()
153153
val wb = WorkbookFactory.create(file)
@@ -160,7 +160,7 @@ public fun DataFrame.Companion.readExcel(
160160
stringColumns?.toFormattingOptions(),
161161
rowsCount,
162162
nameRepairStrategy,
163-
withDefaultHeader,
163+
firstRowIsHeader,
164164
)
165165
}
166166
}
@@ -173,11 +173,11 @@ public fun DataFrame.Companion.readExcel(
173173
* @param skipRows number of rows before header
174174
* @param rowsCount number of rows to read.
175175
* @param nameRepairStrategy handling of column names.
176-
* @param withDefaultHeader make default header
177176
* The default behavior is [NameRepairStrategy.CHECK_UNIQUE].
178-
* However, when withDefaultHeader is set to true,
179-
* it operates as [NameRepairStrategy.MAKE_UNIQUE],
180-
* ensuring unique column names are generated for unstructured data.
177+
* @param firstRowIsHeader when set to true, it will take the first row (after skipRows) as the header.
178+
* when set to false, it operates as [NameRepairStrategy.MAKE_UNIQUE],
179+
* ensuring unique column names will make the columns be named according to excel columns, like "A", "B", "C" etc.
180+
* for unstructured data.
181181
*/
182182
@Refine
183183
@Interpretable("ReadExcel")
@@ -189,7 +189,7 @@ public fun DataFrame.Companion.readExcel(
189189
stringColumns: StringColumns? = null,
190190
rowsCount: Int? = null,
191191
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
192-
withDefaultHeader: Boolean = false,
192+
firstRowIsHeader: Boolean = true,
193193
): AnyFrame =
194194
readExcel(
195195
asURL(fileOrUrl),
@@ -199,7 +199,7 @@ public fun DataFrame.Companion.readExcel(
199199
stringColumns,
200200
rowsCount,
201201
nameRepairStrategy,
202-
withDefaultHeader,
202+
firstRowIsHeader,
203203
)
204204

205205
/**
@@ -210,11 +210,11 @@ public fun DataFrame.Companion.readExcel(
210210
* @param skipRows number of rows before header
211211
* @param rowsCount number of rows to read.
212212
* @param nameRepairStrategy handling of column names.
213-
* @param withDefaultHeader make default header
214213
* The default behavior is [NameRepairStrategy.CHECK_UNIQUE].
215-
* However, when withDefaultHeader is set to true,
216-
* it operates as [NameRepairStrategy.MAKE_UNIQUE],
217-
* ensuring unique column names are generated for unstructured data.
214+
* @param firstRowIsHeader when set to true, it will take the first row (after skipRows) as the header.
215+
* when set to false, it operates as [NameRepairStrategy.MAKE_UNIQUE],
216+
* ensuring unique column names will make the columns be named according to excel columns, like "A", "B", "C" etc.
217+
* for unstructured data.
218218
*/
219219
public fun DataFrame.Companion.readExcel(
220220
inputStream: InputStream,
@@ -224,7 +224,7 @@ public fun DataFrame.Companion.readExcel(
224224
stringColumns: StringColumns? = null,
225225
rowsCount: Int? = null,
226226
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
227-
withDefaultHeader: Boolean = false,
227+
firstRowIsHeader: Boolean = true,
228228
): AnyFrame {
229229
setWorkbookTempDirectory()
230230
val wb = WorkbookFactory.create(inputStream)
@@ -237,7 +237,7 @@ public fun DataFrame.Companion.readExcel(
237237
stringColumns?.toFormattingOptions(),
238238
rowsCount,
239239
nameRepairStrategy,
240-
withDefaultHeader,
240+
firstRowIsHeader,
241241
)
242242
}
243243
}
@@ -251,11 +251,11 @@ public fun DataFrame.Companion.readExcel(
251251
* @param skipRows number of rows before header
252252
* @param rowsCount number of rows to read.
253253
* @param nameRepairStrategy handling of column names.
254-
* @param withDefaultHeader make default header
255254
* The default behavior is [NameRepairStrategy.CHECK_UNIQUE].
256-
* However, when withDefaultHeader is set to true,
257-
* it operates as [NameRepairStrategy.MAKE_UNIQUE],
258-
* ensuring unique column names are generated for unstructured data.
255+
* @param firstRowIsHeader when set to true, it will take the first row (after skipRows) as the header.
256+
* when set to false, it operates as [NameRepairStrategy.MAKE_UNIQUE],
257+
* ensuring unique column names will make the columns be named according to excel columns, like "A", "B", "C" etc.
258+
* for unstructured data.
259259
*/
260260
public fun DataFrame.Companion.readExcel(
261261
wb: Workbook,
@@ -265,12 +265,12 @@ public fun DataFrame.Companion.readExcel(
265265
formattingOptions: FormattingOptions? = null,
266266
rowsCount: Int? = null,
267267
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
268-
withDefaultHeader: Boolean = false,
268+
firstRowIsHeader: Boolean = true,
269269
): AnyFrame {
270270
val sheet: Sheet = sheetName
271271
?.let { wb.getSheet(it) ?: error("Sheet with name $sheetName not found") }
272272
?: wb.getSheetAt(0)
273-
return readExcel(sheet, columns, formattingOptions, skipRows, rowsCount, nameRepairStrategy, withDefaultHeader)
273+
return readExcel(sheet, columns, formattingOptions, skipRows, rowsCount, nameRepairStrategy, firstRowIsHeader)
274274
}
275275

276276
/**
@@ -301,11 +301,11 @@ public class FormattingOptions(range: String, public val formatter: DataFormatte
301301
* @param skipRows number of rows before header
302302
* @param rowsCount number of rows to read.
303303
* @param nameRepairStrategy handling of column names.
304-
* @param withDefaultHeader make default header
305304
* The default behavior is [NameRepairStrategy.CHECK_UNIQUE].
306-
* However, when withDefaultHeader is set to true,
307-
* it operates as [NameRepairStrategy.MAKE_UNIQUE],
308-
* ensuring unique column names are generated for unstructured data.
305+
* @param firstRowIsHeader when set to true, it will take the first row (after skipRows) as the header.
306+
* when set to false, it operates as [NameRepairStrategy.MAKE_UNIQUE],
307+
* ensuring unique column names will make the columns be named according to excel columns, like "A", "B", "C" etc.
308+
* for unstructured data.
309309
*/
310310
public fun DataFrame.Companion.readExcel(
311311
sheet: Sheet,
@@ -314,20 +314,12 @@ public fun DataFrame.Companion.readExcel(
314314
skipRows: Int = 0,
315315
rowsCount: Int? = null,
316316
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
317-
withDefaultHeader: Boolean = false,
317+
firstRowIsHeader: Boolean = true,
318318
): AnyFrame {
319319
val columnIndexes: Iterable<Int> = when {
320-
withDefaultHeader -> {
321-
val notEmptyRow = sheet.rowIterator().asSequence().find { it != null }
322-
checkNotNull(notEmptyRow) {
323-
"There are no defined cells"
324-
}
325-
notEmptyRow.firstCellNum until notEmptyRow.lastCellNum
326-
}
327-
328320
columns != null -> getColumnIndices(columns)
329321

330-
else -> {
322+
firstRowIsHeader -> {
331323
val headerRow = checkNotNull(sheet.getRow(skipRows)) {
332324
"Row number ${skipRows + 1} (1-based index) is not defined on the sheet ${sheet.sheetName}"
333325
}
@@ -337,13 +329,21 @@ public fun DataFrame.Companion.readExcel(
337329
}
338330
headerRow.firstCellNum until headerRow.lastCellNum
339331
}
332+
333+
else -> {
334+
val notEmptyRow = sheet.rowIterator().asSequence().find { it != null }
335+
checkNotNull(notEmptyRow) {
336+
"There are no defined cells"
337+
}
338+
notEmptyRow.firstCellNum until notEmptyRow.lastCellNum
339+
}
340340
}
341341

342-
val headerRow: Row? = if (withDefaultHeader) {
342+
val headerRow: Row? = if (firstRowIsHeader) {
343+
sheet.getRow(skipRows)
344+
} else {
343345
sheet.shiftRows(0, sheet.lastRowNum, 1)
344346
sheet.createRow(0)
345-
} else {
346-
sheet.getRow(skipRows)
347347
}
348348

349349
val first = skipRows + 1
@@ -363,7 +363,7 @@ public fun DataFrame.Companion.readExcel(
363363
val name = repairNameIfRequired(
364364
nameFromCell,
365365
columnNameCounters,
366-
if (withDefaultHeader) NameRepairStrategy.MAKE_UNIQUE else nameRepairStrategy,
366+
if (firstRowIsHeader) nameRepairStrategy else NameRepairStrategy.MAKE_UNIQUE,
367367
)
368368
columnNameCounters[nameFromCell] =
369369
columnNameCounters.getOrDefault(nameFromCell, 0) + 1 // increase the counter for specific column name

0 commit comments

Comments
 (0)