-
Notifications
You must be signed in to change notification settings - Fork 624
get_scenario() and __getitem__ fail to reset MultiIndex for empty components #1402
Copy link
Copy link
Closed
Copy link
Description
Version Checks (indicate both or one)
-
I have confirmed this bug exists on the lastest release of PyPSA.
-
I have confirmed this bug exists on the current
masterbranch of PyPSA.
Issue Description
get_scenario() leaves MultiIndex on empty components, which breaks n.optimize() call.
The problem is specifically here:
Lines 917 to 919 in 8b126b6
| for c in n.components.values(): | |
| if not c.static.empty: | |
| c.static = c.static.xs(scenario, level="scenario", axis=0) |
n['low'] yields the same problem, so __getitem__ has the same issue.
I will patch both via PR in a moment.
Reproducible Example
import pypsa
n = pypsa.Network()
n.set_snapshots(range(3))
n.add("Bus", "bus")
n.add("Load", "load", bus="bus", p_set=100)
n.add("Generator", "gen", bus="bus", p_nom_extendable=True, capital_cost=1000)
n.set_scenarios({"low": 0.5, "high": 0.5})
n_low = n.get_scenario("low") # or n["low"]
n_low.optimize(solver_name="highs") # ValueError: conflicting multi-index level name 'name'
print(n_low.has_scenarios) # False
print(n_low.c.links.static.index) # MultiIndex([], names=['scenario', 'name'])Expected Behavior
Methods should reset MultiIndex and n.optimize() call should work on retrieved networks.
Installed Versions
v1.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels