@@ -157,21 +157,28 @@ def gen_type(
157157 """
158158 # If there's no mapping, we simply make the mapping the sum of both columns
159159 # Read the tech_colors and tech_types csv files.
160+ df = df .copy () # Don't edit the original
160161 try :
161162 tech_types = self .tools .get_dataframe (
162- "graph_tech_types.csv" , from_inputs = True , force_one_scenario = True
163+ "graph_tech_types.csv" , from_inputs = True
163164 )
164165 except FileNotFoundError :
165- df = df .copy ()
166166 df ["gen_type" ] = df [gen_tech_col ] + "_" + df [energy_source_col ]
167167 return df
168- filtered_tech_types = tech_types [tech_types ["map_name" ] == map_name ][
169- ["gen_tech" , "energy_source" , "gen_type" ]
170- ]
168+ tech_types = tech_types [tech_types ["map_name" ] == map_name ].drop (
169+ "map_name" , axis = 1
170+ )
171+ # If we got many scenarios "scenario_name" will exist in tech_types and in that case
172+ # we want to merge by scenario
173+ left_on = [gen_tech_col , energy_source_col ]
174+ right_on = ["gen_tech" , "energy_source" ]
175+ if "scenario_name" in tech_types :
176+ left_on .append ("scenario_name" )
177+ right_on .append ("scenario_name" )
171178 df = df .merge (
172- filtered_tech_types ,
173- left_on = [ gen_tech_col , energy_source_col ] ,
174- right_on = [ "gen_tech" , "energy_source" ] ,
179+ tech_types ,
180+ left_on = left_on ,
181+ right_on = right_on ,
175182 validate = "many_to_one" ,
176183 how = "left" ,
177184 )
0 commit comments