Skip to content

Commit

Permalink
Merge pull request #402 from openego/bugfix/dingo-annual-demand-nans
Browse files Browse the repository at this point in the history
Bugfix/dingo annual demand nans
  • Loading branch information
birgits authored Jul 11, 2024
2 parents 84bc40e + 8bdebe9 commit a65ccdf
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions edisgo/network/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,12 @@ def predefined_conventional_loads_by_sector(
load_names = self._check_if_components_exist(edisgo_object, load_names, "loads")
loads_df = edisgo_object.topology.loads_df.loc[load_names, :]

# check if loads contain annual demand
if not all(loads_df.annual_consumption.notnull()):
raise AttributeError(
"The annual consumption of some loads is missing. Please provide"
)

# scale time series by annual consumption
ts_scaled = loads_df.apply(
lambda x: ts_loads[x.sector] * x.annual_consumption,
Expand Down
20 changes: 20 additions & 0 deletions tests/network/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1794,6 +1794,26 @@ def test_predefined_conventional_loads_by_sector(self, caplog):
).values,
).all()

# test Error if 'annual_consumption' is missing
# Save the original 'annual_consumption' values
original_annual_consumption = self.edisgo.topology.loads_df[
"annual_consumption"
].copy()
# Set 'annual_consumption' to None for the test
self.edisgo.topology.loads_df["annual_consumption"] = None
with pytest.raises(AttributeError) as exc_info:
self.edisgo.timeseries.predefined_conventional_loads_by_sector(
self.edisgo, "demandlib"
)
assert (
exc_info.value.args[0]
== "The annual consumption of some loads is missing. Please provide"
)
# Restore the original 'annual_consumption' values
self.edisgo.topology.loads_df[
"annual_consumption"
] = original_annual_consumption

def test_predefined_charging_points_by_use_case(self, caplog):
index = pd.date_range("1/1/2018", periods=3, freq="H")
self.edisgo.timeseries.timeindex = index
Expand Down

0 comments on commit a65ccdf

Please sign in to comment.