Skip to content

Commit

Permalink
Merge pull request #25 from PALEOtoolkit/fix_empty_parameters
Browse files Browse the repository at this point in the history
bugfix for config file with empty parameters:
  • Loading branch information
sjdaines authored May 19, 2022
2 parents 779d035 + 4d9f7dc commit 8d238f0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "PALEOboxes"
uuid = "804b410e-d900-4b2a-9ecd-f5a06d4c1fd4"
authors = ["Stuart Daines <[email protected]>"]
version = "0.18.5"
version = "0.18.6"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Expand Down
5 changes: 3 additions & 2 deletions src/Reaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,16 @@ function create_reaction_from_config(

# set parameters
allpars = get_parameters(newreaction)
conf_parameters = copy(get(conf_reaction, "parameters", Dict{Any,Any}()))
conf_parameters_raw = get(conf_reaction, "parameters", Dict{Any,Any}()) # empty 'parameters:' will return nothing
conf_parameters = isnothing(conf_parameters_raw) ? Dict{Any, Any}() : copy(conf_parameters_raw)
for par in allpars
rawvalue = par.v
par_modified = false
if par.external && haskey(newreaction.base.external_parameters, par.name)
rawvalue = newreaction.base.external_parameters[par.name]
par_modified = true
end
if !isnothing(conf_parameters) && haskey(conf_parameters, par.name) # empty 'parameters:' will return nothing
if haskey(conf_parameters, par.name)
rawvalue = pop!(conf_parameters, par.name)
par_modified = true
end
Expand Down
19 changes: 18 additions & 1 deletion test/configbase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ model_with_loop:
reactions:


# two reactions that depend on each other - sort_reactions! should fail
model_with_invalid_parameter:
domains:
ocean:
Expand All @@ -81,3 +80,21 @@ model_with_invalid_parameter:
oceanfloor:
reactions:

model_with_empty_parameters:
domains:
ocean:

reactions:
julia_paleo_mock:
class: ReactionPaleoMock
parameters:

variable_links:
phy*: mock_phy*

oceansurface:
reactions:

oceanfloor:
reactions:

8 changes: 8 additions & 0 deletions test/runbasetests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,12 @@ end

@test_throws ErrorException("reaction ocean.julia_paleo_mock has no Parameter(s):\n misspelt_par: something\n") PB.create_model_from_config("configbase.yaml", "model_with_invalid_parameter")

end

@testset "PALEOboxes base empty parameters" begin

model = PB.create_model_from_config("configbase.yaml", "model_with_empty_parameters")

@test length(model.domains) == 3

end

2 comments on commit 8d238f0

@sjdaines
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/60545

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.18.6 -m "<description of version>" 8d238f0881d5e1c92f09456dbc8c087e55c99dec
git push origin v0.18.6

Please sign in to comment.