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 <koen@vesoldo.com>
This commit is contained in:
Koen van Greevenbroek 2021-03-10 18:16:09 +01:00 committed by GitHub
parent df2425d4a0
commit 9048af482f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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'])