Skip to content

Commit

Permalink
load data
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Mar 28, 2024
1 parent c215193 commit aa1cdc4
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions src/MadsIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function checkhash(DATA::DATA)::Bool
end
end

function load_data(filename::AbstractString; sheet::AbstractString="Sheet1", first_row::Union{Nothing,Int}=nothing)::DataFrames.DataFrame
function load_data(filename::AbstractString; dataset="", first_row::Union{Nothing,Int}=nothing)::DataFrames.DataFrame
if !isfile(filename)
@warn("File $(filename) does not exist!")
return DataFrames.DataFrame()
Expand All @@ -60,23 +60,38 @@ function load_data(filename::AbstractString; sheet::AbstractString="Sheet1", fir
end
elseif e == ".xlsx"
try
c = DataFrames.DataFrame(XLSX.readtable(filename, sheet; stop_in_empty_row=false, header=true, first_row=first_row))
catch
@error("Sheet $(sheet) does not exist in $(filename)!")
c = DataFrames.DataFrame()
end
elseif e == ".jld"
try
c = JLD.load(filename, "data")
xb = XLSX.readxlsx(filename)
datasets = XLSX.sheetnames(xb)
println("Available XLSX sheets: $(datasets)")
if dataset in datasets
@info("Dataset $(dataset) loaded from $(filename) ...")
c = DataFrames.DataFrame(XLSX.readtable(filename, dataset; stop_in_empty_row=false, header=true, first_row=first_row))
else
@info("Dataset $(datasets[1]) loaded from $(filename) ...")
c = DataFrames.DataFrame(XLSX.readtable(filename, datasets[1]; stop_in_empty_row=false, header=true, first_row=first_row))
end
catch
@error("Label \"data\" does not exist in $(filename)!")
@error("File $(filename) cannot be opened!")
c = DataFrames.DataFrame()
end
elseif e == ".jld2"
elseif ((e == ".jld") || (e == ".jld2"))
try
c = JLD2.load(filename, "data")
if e == ".jld"
ds = JLD.load(filename)
else
ds = JLD2.load(filename)
end
datasets = keys(ds)
println("Available datasets: $(datasets)")
if dataset in datasets
@info("Dataset $(dataset) loaded from $(filename) ...")
c = ds[dataset]
else
@info("Dataset $(datasets[1]) loaded from $(filename) ...")
c = ds[datasets[1]]
end
catch
@error("Label \"data\" does not exist in $(filename)!")
@error("File $(filename) cannot be opened!")
c = DataFrames.DataFrame()
end
else
Expand Down

0 comments on commit aa1cdc4

Please sign in to comment.