Skip to content

Commit

Permalink
solved binary compatibility issues and renamed notEmptyRow to largestRow
Browse files Browse the repository at this point in the history
  • Loading branch information
Jolanrensen committed Oct 31, 2024
1 parent eb85027 commit e53634e
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ internal const val CREATE_COLUMN = "This function is just here for binary compat

internal const val GUESS_COLUMN_TYPE = "This function is just here for binary compatibility. $MESSAGE_0_16"

public const val DF_READ_EXCEL: String = "This function is just here for binary compatibility. $MESSAGE_0_16"
// endregion

// region WARNING in 0.16, ERROR in 0.17
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.jetbrains.kotlinx.dataframe.api.select
import org.jetbrains.kotlinx.dataframe.codeGen.AbstractDefaultReadMethod
import org.jetbrains.kotlinx.dataframe.codeGen.DefaultReadDfMethod
import org.jetbrains.kotlinx.dataframe.exceptions.DuplicateColumnNamesException
import org.jetbrains.kotlinx.dataframe.util.DF_READ_EXCEL
import java.io.File
import java.io.InputStream
import java.io.OutputStream
Expand Down Expand Up @@ -332,11 +333,11 @@ public fun DataFrame.Companion.readExcel(
}

else -> {
val notEmptyRow = sheet.rowIterator().asSequence().maxByOrNull { it.lastCellNum }
checkNotNull(notEmptyRow) {
val largestRow = sheet.rowIterator().asSequence().maxByOrNull { it.lastCellNum }
checkNotNull(largestRow) {
"There are no defined cells"
}
notEmptyRow.firstCellNum until notEmptyRow.lastCellNum
largestRow.firstCellNum until largestRow.lastCellNum
}
}

Expand Down Expand Up @@ -650,3 +651,137 @@ private fun Cell.setDate(date: JavaDate) {
calStart.time = date
this.setTime(calStart.toInstant().atZone(getUserTimeZone().toZoneId()).toLocalDateTime())
}

// region deprecated

/** For binary compatibility */
@Deprecated(DF_READ_EXCEL, level = DeprecationLevel.HIDDEN)
public fun DataFrame.Companion.readExcel(
url: URL,
sheetName: String? = null,
skipRows: Int = 0,
columns: String? = null,
stringColumns: StringColumns? = null,
rowsCount: Int? = null,
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
): AnyFrame =
readExcel(
url = url,
sheetName = sheetName,
skipRows = skipRows,
columns = columns,
stringColumns = stringColumns,
rowsCount = rowsCount,
nameRepairStrategy = nameRepairStrategy,
firstRowIsHeader = true,
)

/** For binary compatibility */
@Deprecated(DF_READ_EXCEL, level = DeprecationLevel.HIDDEN)
public fun DataFrame.Companion.readExcel(
file: File,
sheetName: String? = null,
skipRows: Int = 0,
columns: String? = null,
stringColumns: StringColumns? = null,
rowsCount: Int? = null,
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
): AnyFrame =
readExcel(
file = file,
sheetName = sheetName,
skipRows = skipRows,
columns = columns,
stringColumns = stringColumns,
rowsCount = rowsCount,
nameRepairStrategy = nameRepairStrategy,
firstRowIsHeader = true,
)

/** For binary compatibility */
@Deprecated(DF_READ_EXCEL, level = DeprecationLevel.HIDDEN)
public fun DataFrame.Companion.readExcel(
fileOrUrl: String,
sheetName: String? = null,
skipRows: Int = 0,
columns: String? = null,
stringColumns: StringColumns? = null,
rowsCount: Int? = null,
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
): AnyFrame =
readExcel(
fileOrUrl = fileOrUrl,
sheetName = sheetName,
skipRows = skipRows,
columns = columns,
stringColumns = stringColumns,
rowsCount = rowsCount,
nameRepairStrategy = nameRepairStrategy,
firstRowIsHeader = true,
)

/** For binary compatibility */
@Deprecated(DF_READ_EXCEL, level = DeprecationLevel.HIDDEN)
public fun DataFrame.Companion.readExcel(
inputStream: InputStream,
sheetName: String? = null,
skipRows: Int = 0,
columns: String? = null,
stringColumns: StringColumns? = null,
rowsCount: Int? = null,
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
): AnyFrame =
readExcel(
inputStream = inputStream,
sheetName = sheetName,
skipRows = skipRows,
columns = columns,
stringColumns = stringColumns,
rowsCount = rowsCount,
nameRepairStrategy = nameRepairStrategy,
firstRowIsHeader = true,
)

/** For binary compatibility */
@Deprecated(DF_READ_EXCEL, level = DeprecationLevel.HIDDEN)
public fun DataFrame.Companion.readExcel(
wb: Workbook,
sheetName: String? = null,
skipRows: Int = 0,
columns: String? = null,
formattingOptions: FormattingOptions? = null,
rowsCount: Int? = null,
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
): AnyFrame =
readExcel(
wb = wb,
sheetName = sheetName,
skipRows = skipRows,
columns = columns,
formattingOptions = formattingOptions,
rowsCount = rowsCount,
nameRepairStrategy = nameRepairStrategy,
firstRowIsHeader = true,
)

/** For binary compatibility */
@Deprecated(DF_READ_EXCEL, level = DeprecationLevel.HIDDEN)
public fun DataFrame.Companion.readExcel(
sheet: Sheet,
columns: String? = null,
formattingOptions: FormattingOptions? = null,
skipRows: Int = 0,
rowsCount: Int? = null,
nameRepairStrategy: NameRepairStrategy = NameRepairStrategy.CHECK_UNIQUE,
): AnyFrame =
readExcel(
sheet = sheet,
columns = columns,
formattingOptions = formattingOptions,
skipRows = skipRows,
rowsCount = rowsCount,
nameRepairStrategy = nameRepairStrategy,
firstRowIsHeader = true,
)

// endregion

0 comments on commit e53634e

Please sign in to comment.