Skip to content

Commit

Permalink
Fix to data dict types (#95)
Browse files Browse the repository at this point in the history
* add fix to data dict types
  • Loading branch information
ccoffrin authored Aug 28, 2023
1 parent 50490ed commit 718181d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ InfrastructureModels.jl Change Log
==================================

### Staged
- nothing
- Fix support for strongly type network data (#92)

### v0.7.7
- Fix support for utf-8 in matlab parser (#91)
Expand Down
2 changes: 1 addition & 1 deletion src/core/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function _populate_ref_it!(refs::Dict{Symbol, <:Any}, data_it::Dict{String, <:An

for (key, item) in nw_data
if !(key in global_keys)
if isa(item, Dict{String, Any}) && _iscomponentdict(item)
if typeof(item) <: Dict{String, <:Any} && _iscomponentdict(item)
item_lookup = Dict{Int, Any}([(parse(Int, k), v) for (k, v) in item])
ref[Symbol(key)] = item_lookup
else
Expand Down
5 changes: 5 additions & 0 deletions test/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ end
@test ref[:it][:foo][:nw][0][:comp][2]["a"] == 3
end

@testset "ref initialize keytype" begin
ref = ref_initialize(generic_si_network_data_native, "foo", Set(["per_unit", "dict"]))
@test keytype(ref[:it][:foo][:nw][0][:comp]) == Int
end


abstract type MyAbstractInfrastructureModel <: AbstractInfrastructureModel end
mutable struct MyInfrastructureModel <: MyAbstractInfrastructureModel @im_fields end
Expand Down
28 changes: 28 additions & 0 deletions test/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@ generic_si_network_data = JSON.parse("""{
}
}""")

# used to check that ref_initialize works correctly with strongly typed data
generic_si_network_data_native = Dict(
"per_unit" => false,
"a" => 1,
"b" => "bloop",
"list" => [1, "two", 3.0, false],
"dict" => Dict("a" => 1, "b" => 2.0, "c" => true, "d" => "bloop"),
"comp" => Dict(
"1" => Dict(
"a" => 1,
"b" => 2,
"c" => "same",
"status" => 1
),
"2" => Dict(
"a" => 3,
"b" => 4,
"c" => "same",
"status" => 0
),
"3" => Dict(
"a" => 5,
"b" => 6,
"c" => "same",
"d" => false
)
)
)

generic_mi_network_data = JSON.parse("""
{
Expand Down

0 comments on commit 718181d

Please sign in to comment.