Skip to content

Commit

Permalink
minor: set sort_keys to false when output to yaml file to make it mor…
Browse files Browse the repository at this point in the history
…e readable; also added some comments

WIP

fixes: PolicyEngine#274
  • Loading branch information
SylviaDu99 committed Nov 23, 2024
1 parent a38dafa commit 731c921
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions policyengine_core/parameters/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Parameter(AtInstantLike):
"""

_exclusion_list = ["parent", "_at_instant_cache"]
"""The keys to be excluded from the node when output to a yaml file."""

def __init__(
self, name: str, data: dict, file_path: Optional[str] = None
Expand Down
3 changes: 2 additions & 1 deletion policyengine_core/parameters/parameter_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class ParameterNode(AtInstantLike):
)

_exclusion_list = ["parent", "_at_instant_cache"]
"""The keys to be excluded from the node when output to a yaml file."""

parent: "ParameterNode" = None
"""The parent of the node, or None if the node is the root of the tree."""
Expand Down Expand Up @@ -298,6 +299,6 @@ def write_yaml(self, file_path: Path) -> yaml:
data = self.get_attr_dict()
try:
with open(file_path, "w") as f:
yaml.dump(data, f, sort_keys=True, Dumper=self.NoAliasDumper)
yaml.dump(data, f, sort_keys=False, Dumper=self.NoAliasDumper)
except Exception as e:
print(f"Error when writing YAML file: {e}")
1 change: 1 addition & 0 deletions policyengine_core/parameters/parameter_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ParameterScale(AtInstantLike):
_allowed_keys = config.COMMON_KEYS.union({"brackets"})

_exclusion_list = ["parent", "_at_instant_cache"]
"""The keys to be excluded from the node when output to a yaml file."""

def __init__(self, name: str, data: dict, file_path: str):
"""
Expand Down

0 comments on commit 731c921

Please sign in to comment.