Skip to content

Commit

Permalink
Rename get_df to read_csv_with_schema and change input to single file…
Browse files Browse the repository at this point in the history
… path
  • Loading branch information
abelsiqueira committed Oct 23, 2023
1 parent 184253b commit 1b480a0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
19 changes: 10 additions & 9 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ input files in the `input_folder`.
"""
function create_parameters_and_sets_from_file(input_folder::AbstractString)
# Read data
assets_data_df = get_df(input_folder, "assets-data.csv", AssetData; header = 2)
assets_profiles_df = get_df(input_folder, "assets-profiles.csv", AssetProfiles; header = 2)
# flows_data_df = get_df(input_folder, "flows-data.csv", FlowData; header = 2)
# flows_profiles_df = get_df(input_folder, "flows-profiles.csv", FlowProfiles; header = 2)
rep_period_df = get_df(input_folder, "rep-periods-data.csv", RepPeriodData; header = 2)
fillpath(filename) = joinpath(input_folder, filename)
assets_data_df = read_csv_with_schema(fillpath("assets-data.csv"), AssetData; header = 2)
assets_profiles_df = read_csv_with_schema(fillpath("assets-profiles.csv"), AssetProfiles; header = 2)
# flows_data_df = read_csv_with_schema(fillpath("flows-data.csv"), FlowData; header = 2)
# flows_profiles_df = read_csv_with_schema(fillpath("flows-profiles.csv"), FlowProfiles; header = 2)
rep_period_df =
read_csv_with_schema(fillpath("rep-periods-data.csv"), RepPeriodData; header = 2)

# Sets and subsets that depend on input data
A = assets = assets_data_df[assets_data_df.active.==true, :].name #assets in the energy system that are active
Expand Down Expand Up @@ -75,16 +77,15 @@ function create_parameters_and_sets_from_file(input_folder::AbstractString)
end

"""
get_df(path, file_name, schema)
read_csv_with_schema(file_path, schema)
Reads the csv with file_name at location path validating the data using the schema.
"""
function get_df(path, file_name, schema; csvargs...)
csv_name = joinpath(path, file_name)
function read_csv_with_schema(file_path, schema; csvargs...)
# Get the schema names and types in the form of Dictionaries
col_types = zip(fieldnames(schema), fieldtypes(schema)) |> Dict
df = CSV.read(
csv_name,
file_path,
DataFrames.DataFrame;
types = col_types,
strict = true,
Expand Down
5 changes: 2 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ end
@testset "Input validation" begin
@testset "Make sure that input validation fails for bad files" begin
dir = joinpath(INPUT_FOLDER, "tiny")
@test_throws ArgumentError TulipaEnergyModel.get_df(
dir,
"bad-assets-data.csv",
@test_throws ArgumentError TulipaEnergyModel.read_csv_with_schema(
joinpath(dir, "bad-assets-data.csv"),
TulipaEnergyModel.AssetData,
)
end
Expand Down

0 comments on commit 1b480a0

Please sign in to comment.