Skip to content

Commit

Permalink
perf: reduce unnecessary object creation
Browse files Browse the repository at this point in the history
  • Loading branch information
jenhagg committed Sep 1, 2022
1 parent 03c6bdd commit 5020d21
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions powersimdata/input/tests/test_input_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@

from powersimdata.input.input_data import InputData

_input_data = InputData()


def test_get_file_components():
s_info = {"id": "123"}
ct_file = InputData()._get_file_path(s_info, "ct")
grid_file = InputData()._get_file_path(s_info, "grid")
ct_file = _input_data._get_file_path(s_info, "ct")
grid_file = _input_data._get_file_path(s_info, "grid")
assert "data/input/123_ct.pkl" == ct_file
assert "data/input/123_grid.mat" == grid_file


def test_check_field():
_check_field = InputData()._check_field
_check_field = _input_data._check_field
_check_field("grid")
_check_field("ct")
with pytest.raises(ValueError):
Expand Down
4 changes: 2 additions & 2 deletions powersimdata/scenario/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class Analyze(Ready):
def __init__(self, scenario):
"""Constructor."""
super().__init__(scenario)

self.refresh(scenario)
self._output_data = OutputData()

def refresh(self, scenario):
print(
Expand Down Expand Up @@ -112,7 +112,7 @@ def print_infeasibilities(self):
)

def _get_data(self, field):
return OutputData().get_data(self._scenario_info["id"], field)
return self._output_data.get_data(self._scenario_info["id"], field)

def get_pg(self):
"""Returns PG data frame.
Expand Down

0 comments on commit 5020d21

Please sign in to comment.