Skip to content

Commit

Permalink
Add test_data_overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
liuly12 committed Oct 2, 2024
1 parent 5b25c33 commit 4f0214f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
Binary file not shown.
18 changes: 14 additions & 4 deletions tests/test_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,23 @@ def test_deny(self):
self.assertDictEqual(d2, reply)

def test_data_read(self):
data_path = "../docs/demo/data/processed/timeries_data.csv"
node = Node(name="", data_input_dict={("temperature", 1): 15})
node.t = 1

self.assertEqual(15, node.get_data_input("temperature"))

def test_data_overrides(self):
data_path = "../docs/demo/data/processed/example_override_data.csv.gz"
input_data = pd.read_csv(data_path)
node = Node(name="", data_input_dict=data_path)
node.t = Node.data_input_dict.keys()[0][1]

overrides = {'data_input_dict': data_path}
node = Node(name="")
node.apply_overrides(overrides)
node.t = list(node.data_input_dict.keys())[0][1]

self.assertEqual(
input_data["temperature"].iloc[0], node.get_data_input("temperature")
input_data.groupby("variable").get_group("temperature")["value"].iloc[0],
node.get_data_input("temperature")
)


Expand Down
2 changes: 1 addition & 1 deletion wsimod/nodes/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def apply_overrides(self, overrides: Dict[str, Any] = {}) -> None:
overrides (dict, optional): Dictionary of overrides. Defaults to {}.
"""
# overrides data_input_dict

content = overrides.pop("data_input_dict", self.data_input_dict)
if isinstance(content, str):
self.data_input_dict = read_csv(content)
Expand Down

0 comments on commit 4f0214f

Please sign in to comment.