Skip to content

Commit

Permalink
Add a check to fix KeyError (PyPSA#220) (PyPSA#228)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
koen-vg and Koen van Greevenbroek authored Mar 10, 2021
1 parent df2425d commit 9048af4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions scripts/add_electricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down

0 comments on commit 9048af4

Please sign in to comment.