From ea61d12eb43502e59894e1fc073615c373593e91 Mon Sep 17 00:00:00 2001 From: Jonas Danke Date: Wed, 3 Jul 2024 14:27:02 +0200 Subject: [PATCH 1/5] Add check for missing annual demand in loads - Raise AttributeError if loads contain missing annual consumption data. --- edisgo/network/timeseries.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/edisgo/network/timeseries.py b/edisgo/network/timeseries.py index 8da353ff..d2059d2d 100644 --- a/edisgo/network/timeseries.py +++ b/edisgo/network/timeseries.py @@ -1448,6 +1448,13 @@ 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 following loads have missing information on annual consumption: " + f"{loads_df[~loads_df.annual_consumption.notnull()].index.values}." + ) + # scale time series by annual consumption ts_scaled = loads_df.apply( lambda x: ts_loads[x.sector] * x.annual_consumption, From 56f32d50bf2506c40a0ebe32225adf4c53575906 Mon Sep 17 00:00:00 2001 From: Jonas Danke Date: Mon, 8 Jul 2024 09:11:57 +0200 Subject: [PATCH 2/5] change AttributeError to Warning for missing annual consumption data --- edisgo/network/timeseries.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/edisgo/network/timeseries.py b/edisgo/network/timeseries.py index d2059d2d..0b7f3999 100644 --- a/edisgo/network/timeseries.py +++ b/edisgo/network/timeseries.py @@ -1450,9 +1450,9 @@ def predefined_conventional_loads_by_sector( # check if loads contain annual demand if not all(loads_df.annual_consumption.notnull()): - raise AttributeError( - "The following loads have missing information on annual consumption: " - f"{loads_df[~loads_df.annual_consumption.notnull()].index.values}." + raise Warning( + "Not all affected loads have information on annual consumption. Please " + "check and adapt if necessary." ) # scale time series by annual consumption From 6ec035345f0633bd76dcebc1e66932a0dec14707 Mon Sep 17 00:00:00 2001 From: Jonas Danke Date: Mon, 8 Jul 2024 12:08:17 +0200 Subject: [PATCH 3/5] Update error handling for missing annual consumption data --- edisgo/network/timeseries.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/edisgo/network/timeseries.py b/edisgo/network/timeseries.py index 0b7f3999..2d8bb0b9 100644 --- a/edisgo/network/timeseries.py +++ b/edisgo/network/timeseries.py @@ -1450,9 +1450,8 @@ def predefined_conventional_loads_by_sector( # check if loads contain annual demand if not all(loads_df.annual_consumption.notnull()): - raise Warning( - "Not all affected loads have information on annual consumption. Please " - "check and adapt if necessary." + raise AttributeError( + "The annual consumption of some loads is missing. Please provide " ) # scale time series by annual consumption From 840af44d8e6b84fc4101760e63a171fbfe53ed1d Mon Sep 17 00:00:00 2001 From: joda9 Date: Wed, 10 Jul 2024 19:15:44 +0200 Subject: [PATCH 4/5] Fix error message typo by removing extra space --- edisgo/network/timeseries.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edisgo/network/timeseries.py b/edisgo/network/timeseries.py index 2d8bb0b9..a2039702 100644 --- a/edisgo/network/timeseries.py +++ b/edisgo/network/timeseries.py @@ -1451,7 +1451,7 @@ def predefined_conventional_loads_by_sector( # 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 " + "The annual consumption of some loads is missing. Please provide" ) # scale time series by annual consumption From b704d2ca30335245cf256dc9554ca6b74bc6b95e Mon Sep 17 00:00:00 2001 From: joda9 Date: Wed, 10 Jul 2024 19:17:02 +0200 Subject: [PATCH 5/5] Add test for missing annual demand --- tests/network/test_timeseries.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/network/test_timeseries.py b/tests/network/test_timeseries.py index 2c05eda4..b06fc945 100644 --- a/tests/network/test_timeseries.py +++ b/tests/network/test_timeseries.py @@ -1793,6 +1793,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