Skip to content

Commit

Permalink
use defaultdict to initialize scaling specification
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyan1214 committed Nov 26, 2024
1 parent c940896 commit 7fa6c0c
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pelicun/model/damage_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

from __future__ import annotations

from collections import defaultdict
from functools import partial
from pathlib import Path
from typing import TYPE_CHECKING
Expand Down Expand Up @@ -1360,12 +1361,12 @@ def parse_scaling_specification(scaling_specification: dict) -> dict: # noqa: C
"""
# if there are contents, ensure they are valid.
# See docstring for an example of what is expected.
parsed_scaling_specification = {}
parsed_scaling_specification = defaultdict(dict)
# validate contents
for key, value in scaling_specification.items():
# loop through limit states
if key not in parsed_scaling_specification:
parsed_scaling_specification[key] = {}
parsed_scaling_specification[key] = defaultdict(list)
if 'ALL' in value:
if len(value) > 1:
msg = (
Expand Down Expand Up @@ -1398,8 +1399,6 @@ def parse_scaling_specification(scaling_specification: dict) -> dict: # noqa: C
if fnumber is None:
msg = f'Invalid number in {css}: {number}'
raise ValueError(msg)
if LS not in parsed_scaling_specification[key]:
parsed_scaling_specification[key][LS] = []
parsed_scaling_specification[key][LS].append(
(capacity_adjustment_operation, fnumber)
)
Expand Down

0 comments on commit 7fa6c0c

Please sign in to comment.