From ec7e9daeaadc7736565e75c03b97b227f28044d1 Mon Sep 17 00:00:00 2001 From: davidanthoff <1036561+davidanthoff@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:17:13 +0000 Subject: [PATCH] Format files using DocumentFormat --- docs/make.jl | 10 +-- src/ExcelReaders.jl | 8 +-- test/test_excelreaders.jl | 144 +++++++++++++++++++------------------- 3 files changed, 81 insertions(+), 81 deletions(-) diff --git a/docs/make.jl b/docs/make.jl index 29bef7baa..5fb3ca6ea 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,10 +1,10 @@ using Documenter, ExcelReaders -makedocs(modules = [ExcelReaders], - sitename = "ExcelReaders.jl", - analytics = "UA-132838790-1", - pages = [ +makedocs(modules=[ExcelReaders], + sitename="ExcelReaders.jl", + analytics="UA-132838790-1", + pages=[ "Introduction" => "index.md" ]) -deploydocs(repo = "github.com/queryverse/ExcelReaders.jl.git") +deploydocs(repo="github.com/queryverse/ExcelReaders.jl.git") diff --git a/src/ExcelReaders.jl b/src/ExcelReaders.jl index 4d9f7a54d..0974a3ecb 100644 --- a/src/ExcelReaders.jl +++ b/src/ExcelReaders.jl @@ -4,7 +4,7 @@ using PyCall, DataValues, Dates export openxl, readxl, readxlsheet, ExcelErrorCell, ExcelFile, readxlnames, readxlrange -const xlrd = PyNULL() +const xlrd = PyNULL() include("package_documentation.jl") @@ -90,7 +90,7 @@ function readxlsheet(file::ExcelFile, sheetname::AbstractString; args...) end # Function converts "relative" range like skip rows/cols and size of range to "absolute" from row/col to row/col -function convert_args_to_row_col(sheet;skipstartrows::Union{Int,Symbol} = :blanks, skipstartcols::Union{Int,Symbol} = :blanks, nrows::Union{Int,Symbol} = :all, ncols::Union{Int,Symbol} = :all) +function convert_args_to_row_col(sheet; skipstartrows::Union{Int,Symbol}=:blanks, skipstartcols::Union{Int,Symbol}=:blanks, nrows::Union{Int,Symbol}=:all, ncols::Union{Int,Symbol}=:all) isa(skipstartrows, Symbol) && skipstartrows != :blanks && error("Only :blank or an integer is a valid argument for skipstartrows") isa(skipstartrows, Int) && skipstartrows < 0 && error("Can't skip a negative number of rows") isa(skipstartcols, Symbol) && skipstartcols != :blanks && error("Only :blank or an integer is a valid argument for skipstartcols") @@ -178,7 +178,7 @@ function convert_ref_to_sheet_row_col(range::AbstractString) endrow = parse(Int, m.captures[6]) endcol = colnum(m.captures[5]) end - if (startrow > endrow ) || (startcol > endcol) + if (startrow > endrow) || (startcol > endcol) error("Please provide rectangular region from top left to bottom right corner") end return sheetname, startrow, startcol, endrow, endcol @@ -234,7 +234,7 @@ function readxl_internal(file::ExcelFile, sheetname::AbstractString, startrow::I for row in startrow:endrow for col in startcol:endcol - data[row - startrow + 1, col - startcol + 1] = get_cell_value(ws, row, col, wb) + data[row-startrow+1, col-startcol+1] = get_cell_value(ws, row, col, wb) end end diff --git a/test/test_excelreaders.jl b/test/test_excelreaders.jl index f28ed9739..e8d7a8d77 100644 --- a/test/test_excelreaders.jl +++ b/test/test_excelreaders.jl @@ -1,7 +1,7 @@ @testitem "ExcelReaders" begin using Dates, PyCall, DataValues -# TODO Throw julia specific exceptions for these errors + # TODO Throw julia specific exceptions for these errors @test_throws PyCall.PyError openxl("FileThatDoesNotExist.xls") @test_throws PyCall.PyError openxl("runtests.jl") @@ -10,7 +10,7 @@ @test file.filename == "TestData.xls" buffer = IOBuffer() - + @test sprint(show, file) == "ExcelFile " for (k, v) in Dict(0 => "#NULL!", 7 => "#DIV/0!", 23 => "#REF!", 42 => "#N/A", 29 => "#NAME?", 36 => "#NUM!", 15 => "#VALUE!") @@ -18,7 +18,7 @@ @test sprint(show, errorcell) == v end -# Read into DataValueArray + # Read into DataValueArray for f in [file, filename] @test_throws ErrorException readxl(f, "Sheet1!C4:G3") @test_throws ErrorException readxl(f, "Sheet1!G2:B5") @@ -26,88 +26,88 @@ data = readxl(f, "Sheet1!C3:N7") @test size(data) == (5, 12) - @test data[4,1] == 2.0 - @test data[2,2] == "A" - @test data[2,3] == true - @test DataValues.isna(data[4,5]) - @test data[2,9] == Date(2015, 3, 3) - @test data[3,9] == DateTime(2015, 2, 4, 10, 14) - @test data[4,9] == DateTime(1988, 4, 9, 0, 0) - @test data[5,9] == Time(15, 2, 0) - @test data[3,10] == DateTime(1950, 8, 9, 18, 40) - @test DataValues.isna(data[5,10]) - @test isa(data[2,11], ExcelErrorCell) - @test isa(data[3,11], ExcelErrorCell) - @test isa(data[4,12], ExcelErrorCell) - @test DataValues.isna(data[5,12]) - - # Test readxlsheet function + @test data[4, 1] == 2.0 + @test data[2, 2] == "A" + @test data[2, 3] == true + @test DataValues.isna(data[4, 5]) + @test data[2, 9] == Date(2015, 3, 3) + @test data[3, 9] == DateTime(2015, 2, 4, 10, 14) + @test data[4, 9] == DateTime(1988, 4, 9, 0, 0) + @test data[5, 9] == Time(15, 2, 0) + @test data[3, 10] == DateTime(1950, 8, 9, 18, 40) + @test DataValues.isna(data[5, 10]) + @test isa(data[2, 11], ExcelErrorCell) + @test isa(data[3, 11], ExcelErrorCell) + @test isa(data[4, 12], ExcelErrorCell) + @test DataValues.isna(data[5, 12]) + + # Test readxlsheet function @test_throws ErrorException readxlsheet(f, "Empty Sheet") for sheetinfo = ["Second Sheet", 2] - @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows = -1) - @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows = :nonsense) + @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows=-1) + @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartrows=:nonsense) - @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols = -1) - @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols = :nonsense) + @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols=-1) + @test_throws ErrorException readxlsheet(f, sheetinfo, skipstartcols=:nonsense) - @test_throws ErrorException readxlsheet(f, sheetinfo, nrows = -1) - @test_throws ErrorException readxlsheet(f, sheetinfo, nrows = :nonsense) + @test_throws ErrorException readxlsheet(f, sheetinfo, nrows=-1) + @test_throws ErrorException readxlsheet(f, sheetinfo, nrows=:nonsense) - @test_throws ErrorException readxlsheet(f, sheetinfo, ncols = -1) - @test_throws ErrorException readxlsheet(f, sheetinfo, ncols = :nonsense) + @test_throws ErrorException readxlsheet(f, sheetinfo, ncols=-1) + @test_throws ErrorException readxlsheet(f, sheetinfo, ncols=:nonsense) data = readxlsheet(f, sheetinfo) @test size(data) == (6, 6) - @test data[2,1] == 1. - @test data[5,2] == "CCC" - @test data[3,3] == false - @test data[6,6] == Time(15, 2, 00) - @test DataValues.isna(data[4,3]) - @test DataValues.isna(data[4,6]) - - data = readxlsheet(f, sheetinfo, skipstartrows = :blanks, skipstartcols = :blanks) + @test data[2, 1] == 1. + @test data[5, 2] == "CCC" + @test data[3, 3] == false + @test data[6, 6] == Time(15, 2, 00) + @test DataValues.isna(data[4, 3]) + @test DataValues.isna(data[4, 6]) + + data = readxlsheet(f, sheetinfo, skipstartrows=:blanks, skipstartcols=:blanks) @test size(data) == (6, 6) - @test data[2,1] == 1. - @test data[5,2] == "CCC" - @test data[3,3] == false - @test data[6,6] == Time(15, 2, 00) - @test DataValues.isna(data[4,3]) - @test DataValues.isna(data[4,6]) - - data = readxlsheet(f, sheetinfo, skipstartrows = 0, skipstartcols = 0) + @test data[2, 1] == 1. + @test data[5, 2] == "CCC" + @test data[3, 3] == false + @test data[6, 6] == Time(15, 2, 00) + @test DataValues.isna(data[4, 3]) + @test DataValues.isna(data[4, 6]) + + data = readxlsheet(f, sheetinfo, skipstartrows=0, skipstartcols=0) @test size(data) == (6 + 7, 6 + 3) - @test data[2 + 7,1 + 3] == 1. - @test data[5 + 7,2 + 3] == "CCC" - @test data[3 + 7,3 + 3] == false - @test data[6 + 7,6 + 3] == Time(15, 2, 00) - @test DataValues.isna(data[4 + 7,3 + 3]) - @test DataValues.isna(data[4 + 7,6 + 3]) - - data = readxlsheet(f, sheetinfo, skipstartrows = 0, ) + @test data[2+7, 1+3] == 1. + @test data[5+7, 2+3] == "CCC" + @test data[3+7, 3+3] == false + @test data[6+7, 6+3] == Time(15, 2, 00) + @test DataValues.isna(data[4+7, 3+3]) + @test DataValues.isna(data[4+7, 6+3]) + + data = readxlsheet(f, sheetinfo, skipstartrows=0,) @test size(data) == (6 + 7, 6) - @test data[2 + 7,1] == 1. - @test data[5 + 7,2] == "CCC" - @test data[3 + 7,3] == false - @test data[6 + 7,6] == Time(15, 2, 00) - @test DataValues.isna(data[4 + 7,3]) - @test DataValues.isna(data[4 + 7,6]) - - data = readxlsheet(f, sheetinfo, skipstartcols = 0) + @test data[2+7, 1] == 1. + @test data[5+7, 2] == "CCC" + @test data[3+7, 3] == false + @test data[6+7, 6] == Time(15, 2, 00) + @test DataValues.isna(data[4+7, 3]) + @test DataValues.isna(data[4+7, 6]) + + data = readxlsheet(f, sheetinfo, skipstartcols=0) @test size(data) == (6, 6 + 3) - @test data[2,1 + 3] == 1. - @test data[5,2 + 3] == "CCC" - @test data[3,3 + 3] == false - @test data[6,6 + 3] == Time(15, 2, 00) - @test DataValues.isna(data[4,3 + 3]) - @test DataValues.isna(data[4,6 + 3]) - - data = readxlsheet(f, sheetinfo, skipstartrows = 1, skipstartcols = 1, nrows = 11, ncols = 7) + @test data[2, 1+3] == 1. + @test data[5, 2+3] == "CCC" + @test data[3, 3+3] == false + @test data[6, 6+3] == Time(15, 2, 00) + @test DataValues.isna(data[4, 3+3]) + @test DataValues.isna(data[4, 6+3]) + + data = readxlsheet(f, sheetinfo, skipstartrows=1, skipstartcols=1, nrows=11, ncols=7) @test size(data) == (11, 7) - @test data[2 + 6,1 + 2] == 1. - @test data[5 + 6,2 + 2] == "CCC" - @test data[3 + 6,3 + 2] == false - @test_throws BoundsError data[6 + 6,6 + 2] == Time(15, 2, 00) - @test DataValues.isna(data[4 + 6,2 + 2]) + @test data[2+6, 1+2] == 1. + @test data[5+6, 2+2] == "CCC" + @test data[3+6, 3+2] == false + @test_throws BoundsError data[6+6, 6+2] == Time(15, 2, 00) + @test DataValues.isna(data[4+6, 2+2]) end end