From 9048af482fdd6cfbe7202efa5561fe6f078c7734 Mon Sep 17 00:00:00 2001 From: Koen van Greevenbroek <74298901+koen-van-greevenbroek@users.noreply.github.com> Date: Wed, 10 Mar 2021 18:16:09 +0100 Subject: [PATCH] Add a check to fix KeyError (#220) (#228) In some cases, in networks with DC links, a non-existing column would be referenced in an empty Dataframe. This commit adds a check for this case. Co-authored-by: Koen van Greevenbroek --- scripts/add_electricity.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/add_electricity.py b/scripts/add_electricity.py index 8fc8ad5c..e16e1766 100755 --- a/scripts/add_electricity.py +++ b/scripts/add_electricity.py @@ -245,6 +245,11 @@ def update_transmission_costs(n, costs, length_factor=1.0, simple_hvdc_costs=Fal if n.links.empty: return dc_b = n.links.carrier == 'DC' + + # If there are no dc links, then the 'underwater_fraction' column + # may be missing. Therefore we have to return here. + if n.links.loc[dc_b].empty: return + if simple_hvdc_costs: costs = (n.links.loc[dc_b, 'length'] * length_factor * costs.at['HVDC overhead', 'capital_cost'])