diff --git a/edisgo/network/timeseries.py b/edisgo/network/timeseries.py index 585240e9..15337f06 100644 --- a/edisgo/network/timeseries.py +++ b/edisgo/network/timeseries.py @@ -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, diff --git a/tests/network/test_timeseries.py b/tests/network/test_timeseries.py index 3818aaf3..4666a836 100644 --- a/tests/network/test_timeseries.py +++ b/tests/network/test_timeseries.py @@ -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