Skip to content

Commit 204deed

Browse files
authored
Deepcopy market object to prevent side-effects in outputs (#658)
1 parent 79c01ad commit 204deed

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/muse/outputs/mca.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def sector_fuel_costs(
263263
technologies = getattr(sector, "technologies", [])
264264
agents = sorted(getattr(sector, "agents", []), key=attrgetter("name"))
265265

266-
agent_market = market.copy()
266+
agent_market = market.copy(deep=True)
267267
if len(technologies) > 0:
268268
for a in agents:
269269
agent_market["consumption"] = (market.consumption * a.quantity).sel(
@@ -366,7 +366,7 @@ def sector_emission_costs(
366366
technologies = getattr(sector, "technologies", [])
367367
agents = sorted(getattr(sector, "agents", []), key=attrgetter("name"))
368368

369-
agent_market = market.copy()
369+
agent_market = market.copy(deep=True)
370370
if len(technologies) > 0:
371371
for a in agents:
372372
agent_market["consumption"] = (market.consumption * a.quantity).sel(
@@ -426,6 +426,8 @@ def sector_lcoe(
426426
from muse.costs import levelized_cost_of_energy as LCOE
427427
from muse.quantities import capacity_to_service_demand, consumption
428428

429+
market = market.copy(deep=True)
430+
429431
# Filtering of the inputs
430432
data_sector: list[xr.DataArray] = []
431433
technologies = getattr(sector, "technologies", [])
@@ -435,7 +437,7 @@ def sector_lcoe(
435437
agents = retro if len(retro) > 0 else new
436438
if len(technologies) > 0:
437439
for agent in agents:
438-
agent_market = market.sel(year=agent.year).copy()
440+
agent_market = market.sel(year=agent.year)
439441
agent_market["consumption"] = agent_market.consumption * agent.quantity
440442
enduses = [
441443
i.strip()
@@ -511,6 +513,8 @@ def sector_eac(
511513
from muse.costs import equivalent_annual_cost as EAC
512514
from muse.quantities import capacity_to_service_demand, consumption
513515

516+
market = market.copy(deep=True)
517+
514518
# Filtering of the inputs
515519
data_sector: list[xr.DataArray] = []
516520
technologies = getattr(sector, "technologies", [])
@@ -520,7 +524,7 @@ def sector_eac(
520524
agents = retro if len(retro) > 0 else new
521525
if len(technologies) > 0:
522526
for agent in agents:
523-
agent_market = market.sel(year=agent.year).copy()
527+
agent_market = market.sel(year=agent.year)
524528
agent_market["consumption"] = agent_market.consumption * agent.quantity
525529
enduses = [
526530
i.strip()

0 commit comments

Comments
 (0)